UNPKG

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