UNPKG

1.93 kBJavaScriptView Raw
1/**
2 * Module : kero dataTable getSelect
3 * Author : liuyk(liuyk@yonyou.com)
4 * Date : 2016-08-01 14:34:01
5 */
6
7
8/**
9 * 获取选中行索引,多选时,只返回第一个行索引
10 */
11const getSelectedIndex = function () {
12 var selectedIndices = this.selectedIndices()
13 if (selectedIndices == null || selectedIndices.length == 0)
14 return -1
15 return selectedIndices[0]
16};
17
18/**
19 *获取选中的所有行索引数组索引
20 */
21const getSelectedIndices = function () {
22 var selectedIndices = this.selectedIndices()
23 if (selectedIndices == null || selectedIndices.length == 0)
24 return []
25 return selectedIndices
26};
27
28/**
29 * 兼容保留,不要用
30 */
31const getSelectedIndexs = function () {
32 return this.getSelectedIndices();
33}
34
35/**
36 * 获取选中行数据
37 */
38const getSelectedDatas = function (withEmptyRow) {
39 var selectedIndices = this.selectedIndices()
40 var datas = []
41 var sIndices = []
42 for (var i = 0, count = selectedIndices.length; i < count; i++) {
43 sIndices.push(selectedIndices[i])
44 }
45 var rows = this.rows();
46 for (var i = 0, count = rows.length; i < count; i++) {
47 if (sIndices.indexOf(i) != -1)
48 datas.push(rows[i].getData())
49 else if (withEmptyRow == true)
50 datas.push(rows[i].getEmptyData())
51 }
52 return datas
53};
54
55/**
56 * 取选中行
57 */
58const getSelectedRows = function (){
59 var selectedIndices = this.selectedIndices();
60 var selectRows = [];
61 var rows = this.rows.peek();
62 var sIndices = []
63 for (var i = 0, count = selectedIndices.length; i < count; i++) {
64 sIndices.push(selectedIndices[i])
65 }
66 for (var i = 0, count = rows.length; i < count; i++) {
67 if (sIndices.indexOf(i) != -1)
68 selectRows.push(rows[i])
69 }
70 return selectRows
71}
72
73export {
74 getSelectedIndex,
75 getSelectedIndices,
76 getSelectedIndexs,
77 getSelectedDatas,
78 getSelectedRows
79}
\No newline at end of file