UNPKG

1.94 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 { utilFunObj } from './util';
8
9/***
10 * 根据索引删除数据行
11 * @param {number} index 需要删除数据行的索引
12 */
13var setRowDelete = function setRowDelete(index) {
14 if (index instanceof Row) {
15 index = this.getIndexByRowId(index.rowId);
16 }
17 this.setRowsDelete([index]);
18};
19
20/***
21 * 删除所有数据行
22 */
23var setAllRowsDelete = function setAllRowsDelete() {
24 var indices = new Array(this.rows().length);
25 for (var i = 0; i < indices.length; i++) {
26 indices[i] = i;
27 }
28 this.setRowsDelete(indices);
29};
30
31/***
32 * 根据索引数组删除数据行
33 * @param {Array} indices 需要删除数据行的索引数组
34 */
35var setRowsDelete = function setRowsDelete(indices) {
36 indices = utilFunObj._formatToIndicesArray(this, indices);
37 indices = indices.sort(function (a, b) {
38 return b - a;
39 });
40 var rowIds = this.getRowIdsByIndices(indices);
41 var rows = this.getRowsByIndices(indices);
42 var ros = this.rows();
43 for (var i = 0; i < indices.length; i++) {
44 var row = this.getRow(indices[i]);
45 if (row.status == Row.STATUS.NEW || this.forceDel) {
46 ros.splice(indices[i], 1);
47 } else {
48 row.setStatus(Row.STATUS.FALSE_DELETE);
49 var temprows = ros.splice(indices[i], 1);
50 ros.push(temprows[0]);
51 }
52 this.updateSelectedIndices(indices[i], '-');
53 this.updateFocusIndex(indices[i], '-');
54 }
55 this.rows(ros);
56 this.updateCurrIndex();
57 this.trigger(DataTable.ON_DELETE, {
58 falseDelete: true,
59 indices: indices,
60 rowIds: rowIds,
61 rows: rows
62 });
63};
64
65export var rowDeleteFunObj = {
66 setRowDelete: setRowDelete,
67 setAllRowsDelete: setAllRowsDelete,
68 setRowsDelete: setRowsDelete
69};
\No newline at end of file