UNPKG

1.87 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 需要删除的数据行对应数组,数组中既可以是索引也可以是row对象
55 * @example
56 * datatable.removeRows([1,2])
57 * datatable.removeRows([row1,row2])
58 */
59const removeRows = function(indices) {
60 this.setRowsDelete(indices)
61}
62
63
64/**
65 * 清空datatable的所有数据以及分页数据以及index
66 * @memberof DataTable
67 * @example
68 * datatable.clear()
69 */
70const clear = function() {
71 this.removeAllRows();
72 this.cachedPages = [];
73 this.totalPages(1);
74 this.pageIndex(0);
75 this.focusIndex(-1);
76 this.selectedIndices([]);
77}
78
79export const removeRowFunObj = {
80 removeRowByRowId: removeRowByRowId,
81 removeRow: removeRow,
82 removeAllRows: removeAllRows,
83 removeRows: removeRows,
84 clear: clear
85}