UNPKG

1.92 kBJavaScriptView Raw
1/**
2 * Module : kero dataTable removeRow
3 * Author : liuyk(liuyk@yonyou.com)
4 * Date : 2016-08-01 14:34:01
5 */
6import { utilFunObj } from './util';
7
8/**
9 * 根据rowId删除指定行
10 * @memberof DataTable
11 * @param {string} rowId 需要删除行的rowId
12 * @example
13 * datatable.removeRowByRowId('rowid1')
14 */
15var removeRowByRowId = function removeRowByRowId(rowId) {
16 var index = this.getIndexByRowId(rowId);
17 if (index != -1) this.removeRow(index);
18};
19
20/**
21 *根据索引删除指定行
22 * @memberof DataTable
23 * @param {number} index 需要删除行的索引
24 * @example
25 * datatable.removeRow(1)
26 */
27var removeRow = function removeRow(index) {
28 if (index instanceof Row) {
29 index = this.getIndexByRowId(index.rowId);
30 }
31 this.removeRows([index]);
32};
33
34/**
35 * 删除所有行
36 * @memberof DataTable
37 * @example
38 * datatable.removeAllRows();
39 */
40var removeAllRows = function removeAllRows() {
41 this.rows([]);
42 this.selectedIndices([]);
43 this.focusIndex(-1);
44 this.trigger(DataTable.ON_DELETE_ALL);
45 this.updateCurrIndex();
46};
47
48/**
49 * 根据索引数据删除多条数据行
50 * @memberof DataTable
51 * @param {array} indices 需要删除的数据行对应数组,数组中既可以是索引也可以是row对象
52 * @example
53 * datatable.removeRows([1,2])
54 * datatable.removeRows([row1,row2])
55 */
56var removeRows = function removeRows(indices) {
57 this.setRowsDelete(indices);
58};
59
60/**
61 * 清空datatable的所有数据以及分页数据以及index
62 * @memberof DataTable
63 * @example
64 * datatable.clear()
65 */
66var clear = function clear() {
67 this.removeAllRows();
68 this.cachedPages = [];
69 this.totalPages(1);
70 this.pageIndex(0);
71 this.focusIndex(-1);
72 this.selectedIndices([]);
73};
74
75export var removeRowFunObj = {
76 removeRowByRowId: removeRowByRowId,
77 removeRow: removeRow,
78 removeAllRows: removeAllRows,
79 removeRows: removeRows,
80 clear: clear
81};
\No newline at end of file