UNPKG

1.85 kBJavaScriptView Raw
1/**
2 * Module : kero dataTable rowDelete
3 * Desc: 不建议使用此库方法
4 * Author : liuyk(liuyk@yonyou.com)
5 * Date : 2016-08-01 14:34:01
6 */
7import {
8 utilFunObj
9} from './util';
10
11/***
12 * 根据索引删除数据行
13 * @param {number} index 需要删除数据行的索引
14 */
15const setRowDelete = function(index) {
16 if (index instanceof Row) {
17 index = this.getIndexByRowId(index.rowId)
18 }
19 this.setRowsDelete([index])
20}
21
22/***
23 * 删除所有数据行
24 */
25const setAllRowsDelete = function() {
26 var indices = new Array(this.rows().length)
27 for (var i = 0; i < indices.length; i++) {
28 indices[i] = i
29 }
30 this.setRowsDelete(indices)
31}
32
33/***
34 * 根据索引数组删除数据行
35 * @param {Array} indices 需要删除数据行的索引数组
36 */
37const setRowsDelete = function(indices) {
38 indices = utilFunObj._formatToIndicesArray(this, indices)
39 indices = indices.sort(function(a, b) {
40 return b - a;
41 });
42 var rowIds = this.getRowIdsByIndices(indices)
43 var rows = this.getRowsByIndices(indices);
44 for (var i = 0; i < indices.length; i++) {
45 var row = this.getRow(indices[i])
46 if (row.status == Row.STATUS.NEW) {
47 this.rows().splice(indices[i], 1);
48 } else {
49 row.setStatus(Row.STATUS.FALSE_DELETE)
50 var temprows = this.rows().splice(indices[i], 1)
51 this.rows().push(temprows[0]);
52 }
53 this.updateSelectedIndices(indices[i], '-');
54 this.updateFocusIndex(indices[i], '-');
55 }
56 this.updateCurrIndex();
57 this.trigger(DataTable.ON_DELETE, {
58 falseDelete: true,
59 indices: indices,
60 rowIds: rowIds,
61 rows: rows
62 })
63
64}
65
66export const rowDeleteFunObj = {
67 setRowDelete: setRowDelete,
68 setAllRowsDelete: setAllRowsDelete,
69 setRowsDelete: setRowsDelete
70}