UNPKG

1.57 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 {_formatToIndicesArray} from './util';
8
9/**
10 * 设置行删除
11 * @param {Object} index
12 */
13const setRowDelete = function (index) {
14 if (index instanceof Row) {
15 index = this.getIndexByRowId(index.rowId)
16 }
17 this.setRowsDelete([index])
18}
19
20/**
21 * 设置所有行删除
22 */
23const setAllRowsDelete = function () {
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 */
35const setRowsDelete = function (indices) {
36 indices = _formatToIndicesArray(this, indices)
37 var rowIds = this.getRowIdsByIndices(indices)
38 this.trigger(DataTable.ON_DELETE, {
39 falseDelete: true,
40 indices: indices,
41 rowIds: rowIds
42 })
43 for (var i = 0; i < indices.length; i++) {
44 var row = this.getRow(indices[i])
45 if (row.status == Row.STATUS.NEW) {
46 this.rows().splice(indices[i], 1);
47 this.updateSelectedIndices(indices[i], '-')
48 this.updateFocusIndex(index, '-')
49 }
50 else {
51 row.status = Row.STATUS.FALSE_DELETE
52 var temprows = this.rows().splice(indices[i], 1)
53 this.rows().push(temprows[0]);
54 }
55 }
56}
57
58export {
59 setRowDelete,
60 setAllRowsDelete,
61 setRowsDelete
62}
\No newline at end of file