Permalink
Browse files

feat: addSimpleData增加参数控制是否选中第一行

  • Loading branch information...
LiuYueKai committed Mar 24, 2017
1 parent a960f58 commit 2aa0a3f66c3febe2c068de9ca462c86109e66e73
Showing with 70 additions and 80 deletions.
  1. +21 −29 dist/kero.js
  2. +1 −1 dist/kero.min.js
  3. +12 −0 lib/getData.js
  4. +1 −0 lib/indexRow.js
  5. +1 −28 lib/removeRow.js
  6. +6 −4 lib/row.js
  7. +11 −7 lib/rowDelete.js
  8. +3 −3 lib/simpleData.js
  9. +6 −3 src/row.js
  10. +8 −5 src/simpleData.js
View
@@ -363,6 +363,7 @@
}
return object;
};
+ Object.assign || (Object.assign = extend);
}, function(module, exports, __webpack_require__) {
var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;
!function(global, factory) {
@@ -785,6 +786,9 @@
}, getChangedRows = function() {
for (var changedRows = [], rows = this.rows.peek(), i = 0, count = rows.length; i < count; i++) rows[i] && rows[i].status != Row.STATUS.NORMAL && changedRows.push(rows[i]);
return changedRows;
+ }, getDeleteRows = function() {
+ for (var deleteRows = [], rows = this.rows.peek(), i = 0, count = rows.length; i < count; i++) rows[i] && rows[i].status == Row.STATUS.FALSE_DELETE && deleteRows.push(rows[i]);
+ return deleteRows;
}, getValue = function(fieldName, row) {
return row = row || this.getCurrentRow(), row ? row.getValue(fieldName) : "";
}, getIndexByRowId = function(rowId) {
@@ -810,6 +814,7 @@
getAllPageRows: getAllPageRows,
getChangedDatas: getChangedDatas,
getChangedRows: getChangedRows,
+ getDeleteRows: getDeleteRows,
getValue: getValue,
getIndexByRowId: getIndexByRowId,
getAllDatas: getAllDatas,
@@ -1433,22 +1438,7 @@
this.rows([]), this.selectedIndices([]), this.focusIndex(-1), this.trigger(DataTable.ON_DELETE_ALL),
this.updateCurrIndex();
}, removeRows = function(indices) {
- indices = _util.utilFunObj._formatToIndicesArray(this, indices), indices = indices.sort(function(a, b) {
- return a - b;
- });
- for (var rowIds = [], rows = this.rows(), deleteRows = [], i = indices.length - 1; i >= 0; i--) {
- var index = indices[i], delRow = rows[index];
- if (null != delRow) {
- rowIds.push(delRow.rowId);
- var deleteRow = rows.splice(index, 1);
- deleteRows.push(deleteRow[0]), this.updateSelectedIndices(index, "-"), this.updateFocusIndex(index, "-");
- }
- }
- this.rows(rows), this.deleteRows = deleteRows, this.trigger(DataTable.ON_DELETE, {
- indices: indices,
- rowIds: rowIds,
- deleteRows: deleteRows
- }), this.updateCurrIndex();
+ this.setRowsDelete(indices);
}, clear = function() {
this.removeAllRows(), this.cachedPages = [], this.totalPages(1), this.pageIndex(0),
this.focusIndex(-1), this.selectedIndices([]);
@@ -1965,11 +1955,12 @@
index: index,
rows: rows
}), this.ns && this.root.valueChange[this.ns] && this.root.valueChange[this.ns](-this.root.valueChange[this.ns]());
- }, createEmptyRow = function() {
+ }, createEmptyRow = function(options) {
var r = new Row({
parent: this
});
- return this.addRow(r), r;
+ return this.addRow(r), !!options && options.unSelect || this.getCurrentRow() || this.setRowSelect(r),
+ r;
};
exports.rowFunObj = {
setRows: setRows,
@@ -2016,22 +2007,23 @@
for (var indices = new Array(this.rows().length), i = 0; i < indices.length; i++) indices[i] = i;
this.setRowsDelete(indices);
}, setRowsDelete = function(indices) {
- indices = _util.utilFunObj._formatToIndicesArray(this, indices);
- var rowIds = this.getRowIdsByIndices(indices);
- this.trigger(DataTable.ON_DELETE, {
- falseDelete: !0,
- indices: indices,
- rowIds: rowIds
+ indices = _util.utilFunObj._formatToIndicesArray(this, indices), indices = indices.sort(function(a, b) {
+ return b - a;
});
- for (var i = 0; i < indices.length; i++) {
+ for (var rowIds = this.getRowIdsByIndices(indices), i = 0; i < indices.length; i++) {
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 {
+ if (row.status == Row.STATUS.NEW) this.rows().splice(indices[i], 1); else {
row.setStatus(Row.STATUS.FALSE_DELETE);
var temprows = this.rows().splice(indices[i], 1);
this.rows().push(temprows[0]);
}
+ this.updateSelectedIndices(indices[i], "-"), this.updateFocusIndex(indices[i], "-");
}
+ this.updateCurrIndex(), this.trigger(DataTable.ON_DELETE, {
+ falseDelete: !0,
+ indices: indices,
+ rowIds: rowIds
+ });
};
exports.rowDeleteFunObj = {
setRowDelete: setRowDelete,
@@ -2200,11 +2192,11 @@
rows: rows
};
options && void 0 === options.fieldFlag && (options.fieldFlag = !0), this.setData(_data, options);
- }, addSimpleData = function(data, status) {
+ }, addSimpleData = function(data, status, options) {
if (!data) throw new Error("dataTable.addSimpleData param can't be null!");
(0, _util.isArray)(data) || (data = [ data ]);
for (var i = 0; i < data.length; i++) {
- this.createEmptyRow().setSimpleData(data[i], status);
+ this.createEmptyRow(options).setSimpleData(data[i], status);
}
};
exports.simpleDataFunObj = {
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -383,6 +383,17 @@
return changedRows;
};
+ const getDeleteRows = function () {
+ var deleteRows = [],
+ rows = this.rows.peek();
+ for (var i = 0, count = rows.length; i < count; i++) {
+ if (rows[i] && rows[i].status == Row.STATUS.FALSE_DELETE) {
+ deleteRows.push(rows[i]);
+ }
+ }
+ return deleteRows;
+ };
+
/**
* 根据字段获取对应Row对象的字段值
* @memberof DataTable
@@ -457,6 +468,7 @@
getAllPageRows: getAllPageRows,
getChangedDatas: getChangedDatas,
getChangedRows: getChangedRows,
+ getDeleteRows: getDeleteRows,
getValue: getValue,
getIndexByRowId: getIndexByRowId,
getAllDatas: getAllDatas,
View
@@ -47,6 +47,7 @@
this.status = Row.STATUS.NEW;
/**
* 当前行对应的DataTable对象
+ * @type {u.DataTable}
*/
this.parent = options['parent'];
// 当前行的数据信息
View
@@ -72,34 +72,7 @@
* datatable.removeRows([1,2])
*/
const removeRows = function (indices) {
- indices = _util.utilFunObj._formatToIndicesArray(this, indices);
- indices = indices.sort(function (a, b) {
- return a - b;
- });
- var rowIds = [],
- rows = this.rows(),
- deleteRows = [];
- for (var i = indices.length - 1; i >= 0; i--) {
- var index = indices[i];
- var delRow = rows[index];
- if (delRow == null) {
- continue;
- }
- rowIds.push(delRow.rowId);
- var deleteRow = rows.splice(index, 1);
- deleteRows.push(deleteRow[0]);
- this.updateSelectedIndices(index, '-');
- this.updateFocusIndex(index, '-');
- }
- this.rows(rows);
- this.deleteRows = deleteRows;
- this.trigger(DataTable.ON_DELETE, {
- indices: indices,
- rowIds: rowIds,
- deleteRows: deleteRows
- });
-
- this.updateCurrIndex();
+ this.setRowsDelete(indices);
};
/**
View
@@ -103,7 +103,7 @@
* field1: 'value11',
* field2: 'value22'
* })
- * datatable.addRow([row1,row2])
+ * datatable.addRows([row1,row2])
*/
const addRows = function (rows) {
this.insertRows(this.rows().length, rows);
@@ -174,13 +174,15 @@
* @example
* datatable.createEmptyRow();
*/
- const createEmptyRow = function () {
+ const createEmptyRow = function (options) {
var r = new Row({
parent: this
});
this.addRow(r);
- // if (!this.getCurrentRow())
- // this.setRowSelect(r);
+ var unSelect = options ? options.unSelect : false;
+ if (!unSelect) {
+ if (!this.getCurrentRow()) this.setRowSelect(r);
+ }
return r;
};
View
@@ -53,24 +53,28 @@
*/
const setRowsDelete = function (indices) {
indices = _util.utilFunObj._formatToIndicesArray(this, indices);
- var rowIds = this.getRowIdsByIndices(indices);
- this.trigger(DataTable.ON_DELETE, {
- falseDelete: true,
- indices: indices,
- rowIds: rowIds
+ indices = indices.sort(function (a, b) {
+ return b - a;
});
+ var rowIds = this.getRowIdsByIndices(indices);
for (var i = 0; i < indices.length; i++) {
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.setStatus(Row.STATUS.FALSE_DELETE);
var temprows = this.rows().splice(indices[i], 1);
this.rows().push(temprows[0]);
}
+ this.updateSelectedIndices(indices[i], '-');
+ this.updateFocusIndex(indices[i], '-');
}
+ this.updateCurrIndex();
+ this.trigger(DataTable.ON_DELETE, {
+ falseDelete: true,
+ indices: indices,
+ rowIds: rowIds
+ });
};
const rowDeleteFunObj = exports.rowDeleteFunObj = {
View
@@ -78,7 +78,7 @@
* 追加数据, 只设置字段值
* @memberof DataTable
* @param {array} data 数据信息
- * @param {string} status 追加数据信息的状态,参照Row对象的状态介绍
+ * @param {string} [status] 追加数据信息的状态,参照Row对象的状态介绍
* @example
* var data = [{
* filed1:'value1',
@@ -94,13 +94,13 @@
* Author : liuyk(liuyk@yonyou.com)
* Date : 2016-08-01 14:34:01
*/
- const addSimpleData = function (data, status) {
+ const addSimpleData = function (data, status, options) {
if (!data) {
throw new Error("dataTable.addSimpleData param can't be null!");
}
if (!(0, _util.isArray)(data)) data = [data];
for (var i = 0; i < data.length; i++) {
- var r = this.createEmptyRow();
+ var r = this.createEmptyRow(options);
r.setSimpleData(data[i], status);
}
};
View
@@ -162,13 +162,16 @@ const insertRows = function(index, rows) {
* @example
* datatable.createEmptyRow();
*/
-const createEmptyRow = function() {
+const createEmptyRow = function(options) {
var r = new Row({
parent: this
})
this.addRow(r)
- // if (!this.getCurrentRow())
- // this.setRowSelect(r);
+ var unSelect = options ? options.unSelect : false;
+ if(!unSelect){
+ if (!this.getCurrentRow())
+ this.setRowSelect(r);
+ }
return r
}
View
@@ -10,7 +10,7 @@ import {isArray} from 'tinper-sparrow/src/util';
* @memberof DataTable
* @param {array} data 数据信息
* @param {boject} [options] 可配置参数
- * @param {boject} [options.unSelect=true] 是否默认选中第一行,如果为true则不选中第一行,否则选中第一行
+ * @param {boject} [options.unSelect=false] 是否默认选中第一行,如果为true则不选中第一行,否则选中第一行
* @example
* var data = [{
* filed1:'value1',
@@ -20,7 +20,7 @@ import {isArray} from 'tinper-sparrow/src/util';
* field2:'value21'
* }]
* datatable.setSimpleData(data)
- * datatable.setSimpleData(data,{unSelect:false})
+ * datatable.setSimpleData(data,{unSelect:true})
*/
const setSimpleData = function(data,options){
this.removeAllRows();
@@ -67,7 +67,9 @@ const setSimpleData = function(data,options){
* 追加数据, 只设置字段值
* @memberof DataTable
* @param {array} data 数据信息
- * @param {string} status 追加数据信息的状态,参照Row对象的状态介绍
+ * @param {string} [status=nrm] 追加数据信息的状态,参照Row对象的状态介绍
+ * @param {boject} [options] 可配置参数
+ * @param {boject} [options.unSelect=false] 是否默认选中第一行,如果为true则不选中第一行,否则选中第一行
* @example
* var data = [{
* filed1:'value1',
@@ -77,15 +79,16 @@ const setSimpleData = function(data,options){
* field2:'value21'
* }]
* datatable.addSimpleData(data,Row.STATUS.NEW)
+ * datatable.addSimpleData(data, null, {unSelect:true})
*/
-const addSimpleData = function(data, status){
+const addSimpleData = function(data, status, options){
if (!data){
throw new Error("dataTable.addSimpleData param can't be null!");
}
if (!isArray(data))
data = [data];
for (var i =0; i< data.length; i++){
- var r = this.createEmptyRow();
+ var r = this.createEmptyRow(options);
r.setSimpleData(data[i],status);
}

0 comments on commit 2aa0a3f

Please sign in to comment.