UNPKG

1.78 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.setRowsDelete = exports.setAllRowsDelete = exports.setRowDelete = undefined;
7
8var _util = require('./util');
9
10/**
11 * 设置行删除
12 * @param {Object} index
13 */
14var setRowDelete = function setRowDelete(index) {
15 if (index instanceof Row) {
16 index = this.getIndexByRowId(index.rowId);
17 }
18 this.setRowsDelete([index]);
19};
20
21/**
22 * 设置所有行删除
23 */
24/**
25 * Module : kero dataTable rowDelete
26 * Desc: 不建议使用此库方法
27 * Author : liuyk(liuyk@yonyou.com)
28 * Date : 2016-08-01 14:34:01
29 */
30var setAllRowsDelete = function setAllRowsDelete() {
31 var indices = new Array(this.rows().length);
32 for (var i = 0; i < indices.length; i++) {
33 indices[i] = i;
34 }
35 this.setRowsDelete(indices);
36};
37
38/**
39 * 设置行删除
40 * @param {Array} indices
41 */
42var setRowsDelete = function setRowsDelete(indices) {
43 indices = (0, _util._formatToIndicesArray)(this, indices);
44 var rowIds = this.getRowIdsByIndices(indices);
45 this.trigger(DataTable.ON_DELETE, {
46 falseDelete: true,
47 indices: indices,
48 rowIds: rowIds
49 });
50 for (var i = 0; i < indices.length; i++) {
51 var row = this.getRow(indices[i]);
52 if (row.status == Row.STATUS.NEW) {
53 this.rows().splice(indices[i], 1);
54 this.updateSelectedIndices(indices[i], '-');
55 this.updateFocusIndex(index, '-');
56 } else {
57 row.status = Row.STATUS.FALSE_DELETE;
58 var temprows = this.rows().splice(indices[i], 1);
59 this.rows().push(temprows[0]);
60 }
61 }
62};
63
64exports.setRowDelete = setRowDelete;
65exports.setAllRowsDelete = setAllRowsDelete;
66exports.setRowsDelete = setRowsDelete;
\No newline at end of file