UNPKG

2.46 kBJavaScriptView Raw
1/**
2 * Module : kero dataTable getSimpleData
3 * Author : liuyk(liuyk@yonyou.com)
4 * Date : 2016-08-01 14:34:01
5 */
6
7/**
8 * 获取数据信息,只获取字段名与字段值
9 * @memberof DataTable
10 * @param {object} [options] [description]
11 * @param {string} [options.type=all] 获取数据的规则
12 * all:所有数据
13 * current:当前行数据
14 * focus:焦点行数据
15 * select:选中行数据
16 * change:发生改变的数据
17 * @param {array} [options.fields] 需要获取数据的字段名数组
18 * @return {array} 获取到的数据信息
19 * @example
20 * datatable.getSimpleData() // 获取所有数据信息
21 * datatable.getSimpleData({type:'current'}) // 获取当前行数据信息
22 * datatable.getSimpleData({type:'current','fields':['filed1','field3']}) // 获取当前行field1和filed3数据信息
23 */
24const getSimpleData = function(options) {
25 options = options || {}
26 var rows, _rowData = [],
27 type = options['type'] || 'all',
28 fields = options['fields'] || null;
29
30 if (type === 'current') {
31 var currRow = this.getCurrentRow();
32 rows = currRow == null ? [] : [currRow];
33 } else if (type === 'focus') {
34 var focusRow = this.getFocusRow();
35 rows = focusRow == null ? [] : [focusRow];
36 } else {
37 if (this.pageCache) {
38 var pages = this.getPages();
39 rows = []
40 for (var i = 0; i < pages.length; i++) {
41 var page = pages[i];
42 if (type === 'all') {
43 rows = rows.concat(page.rows.peek());
44 }else if(type === 'select') {
45 rows = rows.concat(page.getSelectRows());
46 } else if (type === 'change') {
47 rows = rows.concat(page.getSelectRows());
48 }
49 }
50 } else {
51 if (type === 'all') {
52 rows = this.rows.peek();
53 } else if (type === 'select') {
54 rows = this.getSelectedRows();
55 } else if (type === 'change') {
56 rows = this.getChangedRows();
57 }
58 }
59 }
60
61 for (var i = 0; i < rows.length; i++) {
62 _rowData.push(rows[i].getSimpleData({
63 fields: fields
64 }));
65 }
66 if (_rowData.length == 0) {
67 _rowData = this.setSimpleDataReal; //云采提的#需求
68 }
69 return _rowData;
70};
71
72
73
74export const getSimpleDataFunObj = {
75 getSimpleData: getSimpleData
76}