1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | import {_formatToIndicesArray} from './util';
|
7 |
|
8 | const removeRowByRowId = function (rowId) {
|
9 | var index = this.getIndexByRowId(rowId)
|
10 | if (index != -1)
|
11 | this.removeRow(index)
|
12 | }
|
13 |
|
14 | const removeRow = function (index) {
|
15 | if (index instanceof Row) {
|
16 | index = this.getIndexByRowId(index.rowId)
|
17 | }
|
18 | this.removeRows([index]);
|
19 | }
|
20 |
|
21 | const removeAllRows = function () {
|
22 | this.rows([])
|
23 | this.selectedIndices([])
|
24 | this.focusIndex(-1)
|
25 | this.trigger(DataTable.ON_DELETE_ALL)
|
26 | this.updateCurrIndex();
|
27 | }
|
28 |
|
29 | const removeRows = function (indices) {
|
30 | indices = _formatToIndicesArray(this, indices)
|
31 | indices = indices.sort(function(a,b){
|
32 | return a-b;
|
33 | });
|
34 | var rowIds = [], rows = this.rows(), deleteRows = [];
|
35 | for (var i = indices.length - 1; i >= 0; i--) {
|
36 | var index = indices[i]
|
37 | var delRow = rows[index];
|
38 | if (delRow == null) {
|
39 | continue;
|
40 | }
|
41 | rowIds.push(delRow.rowId)
|
42 | var deleteRow = rows.splice(index, 1);
|
43 | deleteRows.push(deleteRow[0]);
|
44 | this.updateSelectedIndices(index, '-')
|
45 | this.updateFocusIndex(index, '-')
|
46 | }
|
47 | this.rows(rows)
|
48 | this.deleteRows = deleteRows;
|
49 | this.trigger(DataTable.ON_DELETE, {
|
50 | indices: indices,
|
51 | rowIds: rowIds,
|
52 | deleteRows: deleteRows
|
53 | })
|
54 |
|
55 | this.updateCurrIndex();
|
56 | }
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | const clear = function () {
|
63 | this.removeAllRows();
|
64 | this.cachedPages = [];
|
65 | this.totalPages(1);
|
66 | this.pageIndex(0);
|
67 | this.focusIndex(-1);
|
68 | this.selectedIndices([]);
|
69 | }
|
70 |
|
71 | export {
|
72 | removeRowByRowId,
|
73 | removeRow,
|
74 | removeAllRows,
|
75 | removeRows,
|
76 | clear
|
77 | } |
\ | No newline at end of file |