Permalink
Browse files

feat: datatable增加resetAllValue、resetValueByRow,row增加setStatus、resetVa…

…lue用以支持重置数据的业务需求
  • Loading branch information...
LiuYueKai committed Mar 16, 2017
1 parent 7823aa0 commit 5b1389855cc64d2fc9d6653de11a0db38edf7136
Showing with 208 additions and 39 deletions.
  1. +34 −12 dist/kero.js
  2. +1 −1 dist/kero.min.js
  3. +59 −3 lib/data.js
  4. +2 −2 lib/page-data.js
  5. +1 −1 lib/page-meta.js
  6. +3 −3 lib/page.js
  7. +37 −2 lib/row-data.js
  8. +1 −1 lib/row-util.js
  9. +1 −1 lib/row.js
  10. +1 −1 lib/rowDelete.js
  11. +21 −1 src/data.js
  12. +2 −2 src/page-data.js
  13. +1 −1 src/page-meta.js
  14. +3 −3 src/page.js
  15. +38 −2 src/row-data.js
  16. +1 −1 src/row-util.js
  17. +1 −1 src/row.js
  18. +1 −1 src/rowDelete.js
@@ -164,7 +164,7 @@
var utcString = Date.parse(date);
return isNaN(utcString) ? "" : utcString;
}, _triggerChange = function(rowObj, fieldName, oldValue, ctx) {
if (_getField(rowObj, fieldName).changed = !0, rowObj.status != Row.STATUS.NEW && (rowObj.status = Row.STATUS.UPDATE),
if (_getField(rowObj, fieldName).changed = !0, rowObj.status != Row.STATUS.NEW && rowObj.setStatus(Row.STATUS.UPDATE),
rowObj.valueChange[fieldName] && rowObj.valueChange[fieldName](-rowObj.valueChange[fieldName]()),
rowObj.parent.getCurrentRow() == rowObj && rowObj.parent.valueChange[fieldName] && rowObj.parent.valueChange[fieldName](-rowObj.parent.valueChange[fieldName]()),
rowObj.parent.ns) {
@@ -580,10 +580,16 @@
void 0 !== focus && this.getRow(focus) && this.setRowFocus(focus);
}, setValue = function(fieldName, value, row, ctx) {
1 === arguments.length && (value = fieldName, fieldName = "$data"), (row = row ? row : this.getCurrentRow()) && row.setValue(fieldName, value, ctx);
}, resetAllValue = function() {
for (var rows = this.rows(), i = 0; i < rows.length; i++) rows[i].resetValue();
}, resetValueByRow = function(row) {
row.resetValue();
};
exports.dataFunObj = {
setData: setData,
setValue: setValue
setValue: setValue,
resetAllValue: resetAllValue,
resetValueByRow: resetValueByRow
};
});
}, function(module, exports, __webpack_require__) {
@@ -1051,9 +1057,9 @@
});
var setRowValue = function(rowIndex, fieldName, value) {
var row = this.rows[rowIndex];
row && (row.data[fieldName].value = value, row.status != Row.STATUS.NEW && (row.status = Row.STATUS.UPDATE));
row && (row.data[fieldName].value = value, row.status != Row.STATUS.NEW && row.setStatus(Row.STATUS.UPDATE));
}, updateRow = function(originRow, newRow) {
if (originRow.status = originRow.status, newRow.data) for (var key in newRow.data) if (originRow.data[key]) {
if (newRow.data) for (var key in newRow.data) if (originRow.data[key]) {
var valueObj = newRow.data[key];
if ("string" == typeof valueObj || "number" == typeof valueObj || null === valueObj) originRow.data[key].value = valueObj; else if (valueObj.error) u.showMessageDialog ? u.showMessageDialog({
title: "警告",
@@ -1158,7 +1164,7 @@
var row = this.rows[rowIndex];
if (row) {
var meta = row[fieldName].meta;
meta || (meta = row[fieldName].meta = {}), meta[metaName] = value, row.status != Row.STATUS.NEW && (row.status = Row.STATUS.UPDATE);
meta || (meta = row[fieldName].meta = {}), meta[metaName] = value, row.status != Row.STATUS.NEW && row.setStatus(Row.STATUS.UPDATE);
}
};
exports.pageMetaFunObj = {
@@ -1230,8 +1236,8 @@
}
this.removeRowByRowId(r.id), page.removeRowByRowId(r.id);
} else if (row = page.getRowByRowId(r.id)) page.updateRow(row, r), row.status == Row.STATUS.NEW && r.status != Row.STATUS.NEW && (this.newCount -= 1,
this.newCount < 0 && (this.newCount = 0)), row.status = Row.STATUS.NORMAL, r.status == Row.STATUS.NEW && (row.status = Row.STATUS.NEW); else {
r.rowId = r.id, delete r.id, page.rows.push(r), r.status != Row.STATUS.NEW ? r.status = Row.STATUS.NORMAL : this.newCount += 1;
this.newCount < 0 && (this.newCount = 0)), row.setStatus(Row.STATUS.NORMAL), r.status == Row.STATUS.NEW && row.setStatus(Row.STATUS.NEW); else {
r.rowId = r.id, delete r.id, page.rows.push(r), r.status != Row.STATUS.NEW ? row.setStatus(Row.STATUS.NORMAL) : this.newCount += 1;
var oldTotalRow = this.totalRow(), newTotalRow = oldTotalRow + 1;
this.totalRow(newTotalRow);
}
@@ -1527,9 +1533,9 @@
} else _parentKey = null == _parentKey ? key : _parentKey + "." + key, _setData(rowObj, valueObj, targetData[key], null, _parentKey, options);
}
}, setData = function(data, subscribe, options) {
this.status = data.status;
var sourceData = data.data, targetData = this.data;
if (1 != this.parent.root.strict) return void _setData(this, sourceData, targetData, subscribe, null, options);
if (1 != this.parent.root.strict) return _setData(this, sourceData, targetData, subscribe, null, options),
void this.setStatus(data.status);
var meta = this.parent.meta;
for (var key in meta) {
var oldValue = newValue = null;
@@ -1563,13 +1569,29 @@
}
}, updateRow = function(row) {
this.setData(row);
}, setStatus = function(status) {
if (this.status = status, status == Row.STATUS.NORMAL) {
var data = this.data;
for (var field in data) {
var value = data[field].value;
data[field].baseValue = value;
}
}
}, resetValue = function() {
var data = this.data;
for (var field in data) {
var value = data[field].baseValue;
this.setValue(field, value);
}
};
exports.rowDataFunObj = {
setValue: setValue,
setChildValue: setChildValue,
setChildSimpleDataByRowId: setChildSimpleDataByRowId,
setData: setData,
updateRow: updateRow
updateRow: updateRow,
setStatus: setStatus,
resetValue: resetValue
};
});
}, function(module, exports, __webpack_require__) {
@@ -1924,7 +1946,7 @@
})) : row.currentRowChange(-row.currentRowChange()))) : (row = new Row({
parent: this,
id: _id
}), row.setData(rows[i], null, options), insertRows.push(row)), r.status && (row.status = r.status);
}), row.setData(rows[i], null, options), insertRows.push(row)), r.status && row.setStatus(r.status);
}
}
return insertRows.length > 0 && this.addRows(insertRows), insertRows;
@@ -2005,7 +2027,7 @@
var row = this.getRow(indices[i]);
if (row.status == Row.STATUS.NEW) this.rows().splice(indices[i], 1), this.updateSelectedIndices(indices[i], "-"),
this.updateFocusIndex(index, "-"); else {
row.status = Row.STATUS.FALSE_DELETE;
row.setStatus(Row.STATUS.FALSE_DELETE);
var temprows = this.rows().splice(indices[i], 1);
this.rows().push(temprows[0]);
}

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -37,15 +37,51 @@
* @param {object} options 设置数据时的配置参数
* @param {boolean} options.unSelect=false 是否默认选中第一行,如果为true则不选中第一行,否则选中第一行
* @example
* // 不包含分页的情况
* var data = {
* pageIndex:0,
* pageSize:5,
* totalPages:5,
* totalRow:22,
* rows:[{
* id:'r41201', // 如果需要添加
* status:'nrm', // 如果需要添加
* filed1:'value1',
* field2:'value2'
* },{
* id:'r41202',
* status:'nrm',
* filed1:'value11',
* field2:'value21'
* }],
* select:0,
* },...],
* select:[0]
* }
* // 包含分页的情况
* var data = {
* pageIndex:0,
* pageSize:5,
* totalPages:5,
* totalRow:22,
* pages:[{
* index: 0,
* select: [],
* current: -1,
* rows:[{
* id:'r41201', // 如果需要添加
* status:'nrm', // 如果需要添加
* data:{
* field1:'value1',
* field2:'value2'
* }
* },{
* id:'r41202',
* status:'nrm',
* data:{
* field1:'value11',
* field2:'value21'
* }
* },...]
* },...],
* }
* var op = {
* unSelect:true
@@ -140,8 +176,28 @@
if (row) row.setValue(fieldName, value, ctx);
};

/**
* 重置所有行的数据至nrm状态时的数据
*/
const resetAllValue = function () {
var rows = this.rows();
for (var i = 0; i < rows.length; i++) {
rows[i].resetValue();
}
};

/**
* 根据row对象重置数据至nrm状态时的数据
* @param {u.row} row 需要重置数据的row对象
*/
const resetValueByRow = function (row) {
row.resetValue();
};

const dataFunObj = exports.dataFunObj = {
setData: setData,
setValue: setValue
setValue: setValue,
resetAllValue: resetAllValue,
resetValueByRow: resetValueByRow
};
});
@@ -35,13 +35,13 @@
var row = this.rows[rowIndex];
if (row) {
row.data[fieldName]['value'] = value;
if (row.status != Row.STATUS.NEW) row.status = Row.STATUS.UPDATE;
if (row.status != Row.STATUS.NEW) row.setStatus(Row.STATUS.UPDATE);
}
};

// 通过row对象更新row对象,不建议次方法
const updateRow = function (originRow, newRow) {
originRow.status = originRow.status;
// originRow.status = originRow.status
//this.rowId = data.rowId
if (!newRow.data) return;
for (var key in newRow.data) {
@@ -38,7 +38,7 @@
var meta = row[fieldName].meta;
if (!meta) meta = row[fieldName].meta = {};
meta[metaName] = value;
if (row.status != Row.STATUS.NEW) row.status = Row.STATUS.UPDATE;
if (row.status != Row.STATUS.NEW) row.setStatus(Row.STATUS.UPDATE);
}
};

@@ -104,16 +104,16 @@
this.newCount -= 1;
if (this.newCount < 0) this.newCount = 0;
}
row.status = Row.STATUS.NORMAL;
row.setStatus(Row.STATUS.NORMAL);
if (r.status == Row.STATUS.NEW) {
row.status = Row.STATUS.NEW;
row.setStatus(Row.STATUS.NEW);
}
} else {
r.rowId = r.id;
delete r.id;
page.rows.push(r);
if (r.status != Row.STATUS.NEW) {
r.status = Row.STATUS.NORMAL;
row.setStatus(Row.STATUS.NORMAL);
} else {
this.newCount += 1;
}
@@ -195,6 +195,7 @@
* @param {boolean} [subscribe] 是否触发监听,true表示触发监听
* @param {object} [options] 设置数据信息是的配置参数
* @param {boolean} [options.fieldFlag] 未设置的meta是否进行存储,如果为true则未设置的meta也进行存储
* @example
* var data = {
* filed1:'value1',
* field2:'value2'
@@ -204,11 +205,11 @@
* row.setData(data),false,{fieldFlag:true})
*/
const setData = function (data, subscribe, options) {
this.status = data.status;
var sourceData = data.data,
targetData = this.data;
if (this.parent.root.strict != true) {
_setData(this, sourceData, targetData, subscribe, null, options);
this.setStatus(data.status);
return;
}

@@ -276,11 +277,45 @@
this.setData(row);
};

/**
* 设置row的status属性
* @memberof Row
* @param {string} status 需要设置的status
* @example
* row.setStatus(Row.STATUS.NORMAL)
*/
const setStatus = function (status) {
this.status = status;
if (status == Row.STATUS.NORMAL) {
// 保存baseValue,用于重置
var data = this.data;
for (var field in data) {
var value = data[field].value;
data[field].baseValue = value;
}
}
};

/**
* 重置数据至nrm状态时的数据
* @example
* row.resetValue()
*/
const resetValue = function () {
var data = this.data;
for (var field in data) {
var value = data[field].baseValue;
this.setValue(field, value);
}
};

const rowDataFunObj = exports.rowDataFunObj = {
setValue: setValue,
setChildValue: setChildValue,
setChildSimpleDataByRowId: setChildSimpleDataByRowId,
setData: setData,
updateRow: updateRow
updateRow: updateRow,
setStatus: setStatus,
resetValue: resetValue
};
});
@@ -70,7 +70,7 @@
// 触发数值改变事件
const _triggerChange = function (rowObj, fieldName, oldValue, ctx) {
_getField(rowObj, fieldName).changed = true;
if (rowObj.status != Row.STATUS.NEW) rowObj.status = Row.STATUS.UPDATE;
if (rowObj.status != Row.STATUS.NEW) rowObj.setStatus(Row.STATUS.UPDATE);
if (rowObj.valueChange[fieldName]) rowObj.valueChange[fieldName](-rowObj.valueChange[fieldName]());
if (rowObj.parent.getCurrentRow() == rowObj && rowObj.parent.valueChange[fieldName]) {
rowObj.parent.valueChange[fieldName](-rowObj.parent.valueChange[fieldName]());
@@ -59,7 +59,7 @@
}
// 如果r对象中存在状态则更新状态为返回的状态
if (r.status) {
row.status = r.status;
row.setStatus(r.status);
}
}
}
@@ -66,7 +66,7 @@
this.updateSelectedIndices(indices[i], '-');
this.updateFocusIndex(index, '-');
} else {
row.status = Row.STATUS.FALSE_DELETE;
row.setStatus(Row.STATUS.FALSE_DELETE);
var temprows = this.rows().splice(indices[i], 1);
this.rows().push(temprows[0]);
}
@@ -165,8 +165,28 @@ const setValue = function(fieldName, value, row, ctx) {
row.setValue(fieldName, value, ctx)
}

/**
* 重置所有行的数据至nrm状态时的数据
*/
const resetAllValue = function() {
var rows = this.rows();
for (var i = 0; i < rows.length; i++) {
rows[i].resetValue();
}
}

/**
* 根据row对象重置数据至nrm状态时的数据
* @param {u.row} row 需要重置数据的row对象
*/
const resetValueByRow = function(row) {
row.resetValue();

}

export const dataFunObj = {
setData: setData,
setValue: setValue
setValue: setValue,
resetAllValue: resetAllValue,
resetValueByRow: resetValueByRow
}
@@ -18,15 +18,15 @@ const setRowValue = function(rowIndex, fieldName, value) {
if (row) {
row.data[fieldName]['value'] = value
if (row.status != Row.STATUS.NEW)
row.status = Row.STATUS.UPDATE
row.setStatus(Row.STATUS.UPDATE)
}
}



// 通过row对象更新row对象,不建议次方法
const updateRow = function(originRow, newRow) {
originRow.status = originRow.status
// originRow.status = originRow.status
//this.rowId = data.rowId
if (!newRow.data) return;
for (var key in newRow.data) {
Oops, something went wrong.

0 comments on commit 5b13898

Please sign in to comment.