UNPKG

2.53 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.updateFocusIndex = exports.updateSelectedIndices = exports.removeRowByRowId = undefined;
7
8var _util = require('tinper-sparrow/src/util');
9
10var removeRowByRowId = function removeRowByRowId(rowid) {
11 for (var i = 0, count = this.rows.length; i < count; i++) {
12 if (this.rows[i].rowId == rowid) {
13 this.rows.splice(i, 1);
14 count--;
15 this.updateSelectedIndices(i, '-');
16 this.updateFocusIndex(i, '-');
17 }
18 }
19};
20
21/**
22 * [updateSelectedIndices 更新选中行]
23 * @param {[type]} index [起始行号]
24 * @param {[type]} type [增减类型]
25 * @param {[type]} num [影响行数]
26 */
27/**
28 * Module : kero dataTable page removeRow
29 * Author : liuyk(liuyk@yonyou.com)
30 * Date : 2016-08-08 09:59:01
31 */
32
33var updateSelectedIndices = function updateSelectedIndices(index, type, num) {
34 if (!(0, _util.isNumber)(num)) {
35 num = 1;
36 }
37 var selectedIndices = this.selectedIndices.slice();
38 if (selectedIndices == null || selectedIndices.length == 0) return;
39 for (var i = 0, count = selectedIndices.length; i < count; i++) {
40 if (type == '+') {
41 if (selectedIndices[i] >= index) selectedIndices[i] = parseInt(selectedIndices[i]) + num;
42 } else if (type == '-') {
43 if (selectedIndices[i] >= index && selectedIndices[i] <= index + num - 1) {
44 selectedIndices.splice(i, 1);
45 } else if (selectedIndices[i] > index + num - 1) selectedIndices[i] = selectedIndices[i] - num;
46 }
47 }
48 this.selectedIndices = selectedIndices;
49};
50
51/**
52 * [updateFocusIndex 更新focus行]
53 * @param {[type]} opIndex [起始行号]
54 * @param {[type]} opType [增减类型]
55 * @param {[type]} num [影响行数]
56 */
57var updateFocusIndex = function updateFocusIndex(opIndex, opType, num) {
58 if (!(0, _util.isNumber)(num)) {
59 num = 1;
60 }
61 if (opIndex <= this.focus && this.focus != -1) {
62 if (opType === '+') {
63 this.focus = this.focus + num;
64 } else if (opType === '-') {
65 if (this.focus >= opIndex && this.focus <= opIndex + num - 1) {
66 this.focus = this.focus - 1;
67 } else if (this.focus > opIndex + num - 1) {
68 this.focus = this.focus - num;
69 }
70 }
71 }
72};
73
74exports.removeRowByRowId = removeRowByRowId;
75exports.updateSelectedIndices = updateSelectedIndices;
76exports.updateFocusIndex = updateFocusIndex;
\No newline at end of file