UNPKG

3.13 kBJavaScriptView Raw
1/**
2 * Module : kero dataTable page getData
3 * Author : liuyk(liuyk@yonyou.com)
4 * Date : 2016-08-08 09:59:01
5 */
6
7/**
8 * 获取Page的数据信息
9 * @memberof Page
10 * @return {array} 数据信息对应的数组,每项对应一条数据
11 * @example
12 * page.getData()
13 */
14const getData = function() {
15 var datas = [],
16 row, meta;
17 meta = this.parent.getMeta()
18 for (var i = 0; i < this.rows.length; i++) {
19 row = this.rows[i];
20 datas.push({
21 'id': row.rowId,
22 'status': row.status,
23 data: row.data
24 });
25 }
26 return datas
27}
28
29
30/**
31 * 获取Page的选中行数据信息
32 * @memberof Page
33 * @return {array} 数据信息对应的数组,每项对应一条数据
34 * @example
35 * page.getSelectDatas()
36 */
37const getSelectDatas = function() {
38 var datas = [],
39 row;
40 for (var i = 0; i < this.rows.length; i++) {
41 row = this.rows[i];
42 datas.push({
43 'id': row.rowId,
44 'status': row.status,
45 data: row.data
46 });
47 }
48 for (var i = 0; i < this.selectedIndices.length; i++) {
49 row = this.rows[this.selectedIndices[i]];
50 datas.push({
51 'id': row.rowId,
52 'status': row.status,
53 data: row.data
54 });
55 }
56 return datas
57}
58
59
60/**
61 * 获取Page的选中Row对象
62 * @memberof Page
63 * @return {array} Row对象对应的数组,每项对应一条数据
64 * @example
65 * page.getSelectRows()
66 */
67const getSelectRows = function() {
68 var rows = [];
69 for (var i = 0; i < this.selectedIndices.length; i++) {
70 rows.push(this.rows[this.selectedIndices[i]])
71 }
72 return rows
73}
74
75
76/**
77 * 获取发生改变的Row对象
78 * @memberof DataTable
79 * @return {array} 发生改变的Row对象
80 * @example
81 * datatable.getChangedRows()
82 */
83const getChangedRows = function() {
84 var changedRows = [],
85 rows = this.rows.peek();
86 for (var i = 0, count = rows.length; i < count; i++) {
87 if (rows[i] && rows[i].status != Row.STATUS.NORMAL) {
88 changedRows.push(rows[i])
89 }
90 }
91 return changedRows
92}
93/**
94 * 根据rowid获取Row对象
95 * @memberof Page
96 * @param {string} rowid 需要获取的Row对应的rowid
97 * @returns {Row} Row对象
98 * @example
99 * page.getRowByRowId('rowid')
100 */
101const getRowByRowId = function(rowid) {
102 for (var i = 0, count = this.rows.length; i < count; i++) {
103 if (this.rows[i].rowId == rowid)
104 return this.rows[i]
105 }
106 return null
107}
108
109/**
110 * 根据行索引获取对应行的字段值
111 * @memberof Page
112 * @param {number} rowIndex 行索引
113 * @param {string} fieldName 字段名
114 * @returns {sting} 字段值
115 * @example
116 * page.getRowValue(1,'field1')
117 */
118const getRowValue = function(rowIndex, fieldName) {
119 var row = this.rows[rowIndex]
120 if (row) {
121 return row.data[fieldName]['value']
122 }
123 return null
124}
125
126export const pageGetDataFunObj = {
127 getData: getData,
128 getSelectDatas: getSelectDatas,
129 getSelectRows: getSelectRows,
130 getChangedRows: getChangedRows,
131 getRowByRowId: getRowByRowId,
132 getRowValue: getRowValue
133}