Skip to content

Commit

Permalink
feat: datatable对象的getSimpleData支持跨页选择后获取选中数据
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuYueKai committed Jun 14, 2017
1 parent 0a7ae79 commit 3fae27e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/getSimpleData.js
Expand Up @@ -27,18 +27,35 @@ const getSimpleData = function(options) {
type = options['type'] || 'all',
fields = options['fields'] || null;

if (type === 'all') {
rows = this.rows.peek();
} else if (type === 'current') {
if (type === 'current') {
var currRow = this.getCurrentRow();
rows = currRow == null ? [] : [currRow];
} else if (type === 'focus') {
var focusRow = this.getFocusRow();
rows = focusRow == null ? [] : [focusRow];
} else if (type === 'select') {
rows = this.getSelectedRows();
} else if (type === 'change') {
rows = this.getChangedRows();
} else {
if (this.pageCache) {
var pages = this.getPages();
rows = []
for (var i = 0; i < pages.length; i++) {
var page = pages[i];
if (type === 'all') {
rows = rows.concat(page.rows.peek());
}else if(type === 'select') {
rows = rows.concat(page.getSelectRows());
} else if (type === 'change') {
rows = rows.concat(page.getSelectRows());
}
}
} else {
if (type === 'all') {
rows = this.rows.peek();
} else if (type === 'select') {
rows = this.getSelectedRows();
} else if (type === 'change') {
rows = this.getChangedRows();
}
}
}

for (var i = 0; i < rows.length; i++) {
Expand Down
19 changes: 19 additions & 0 deletions src/page-getData.js
Expand Up @@ -72,6 +72,24 @@ const getSelectRows = function() {
return rows
}


/**
* 获取发生改变的Row对象
* @memberof DataTable
* @return {array} 发生改变的Row对象
* @example
* datatable.getChangedRows()
*/
const getChangedRows = function() {
var changedRows = [],
rows = this.rows.peek();
for (var i = 0, count = rows.length; i < count; i++) {
if (rows[i] && rows[i].status != Row.STATUS.NORMAL) {
changedRows.push(rows[i])
}
}
return changedRows
}
/**
* 根据rowid获取Row对象
* @memberof Page
Expand Down Expand Up @@ -109,6 +127,7 @@ export const pageGetDataFunObj = {
getData: getData,
getSelectDatas: getSelectDatas,
getSelectRows: getSelectRows,
getChangedRows: getChangedRows,
getRowByRowId: getRowByRowId,
getRowValue: getRowValue
}

0 comments on commit 3fae27e

Please sign in to comment.