UNPKG

2.26 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.updateFocusIndex = exports.setRowUnFocus = exports.setRowFocus = undefined;
7
8var _util = require('tinper-sparrow/src/util');
9
10/**
11 * 设置焦点行
12 * @param {Object} index 行对象或者行index
13 * @param quiet 不触发事件
14 * @param force 当index行与已focus的行相等时,仍然触发事件
15 */
16var setRowFocus = function setRowFocus(index, quiet, force) {
17 var rowId = null;
18 if (index instanceof Row) {
19 index = this.getIndexByRowId(index.rowId);
20 rowId = index.rowId;
21 }
22 if (index === -1 || index === this.focusIndex() && !force) {
23 return;
24 }
25 this.focusIndex(index);
26 if (quiet) {
27 return;
28 }
29 this.currentRowChange(-this.currentRowChange());
30 if (!rowId) {
31 rowId = this.getRow(index).rowId;
32 }
33 this.trigger(DataTable.ON_ROW_FOCUS, {
34 index: index,
35 rowId: rowId
36 });
37 this.updateCurrIndex();
38};
39
40/**
41 * 焦点行反选
42 */
43/**
44 * Module : kero dataTable rowFocus
45 * Author : liuyk(liuyk@yonyou.com)
46 * Date : 2016-08-08 09:59:01
47 */
48var setRowUnFocus = function setRowUnFocus() {
49 this.currentRowChange(-this.currentRowChange());
50 var indx = this.focusIndex(),
51 rowId = null;
52 if (indx !== -1) {
53 rowId = this.getRow(indx).rowId;
54 }
55 this.trigger(DataTable.ON_ROW_UNFOCUS, {
56 index: indx,
57 rowId: rowId
58 });
59 this.focusIndex(-1);
60 this.updateCurrIndex();
61};
62
63var updateFocusIndex = function updateFocusIndex(opIndex, opType, num) {
64 if (!(0, _util.isNumber)(num)) {
65 num = 1;
66 }
67 if (opIndex <= this.focusIndex() && this.focusIndex() != -1) {
68 if (opType === '+') {
69 this.focusIndex(this.focusIndex() + num);
70 } else if (opType === '-') {
71 if (this.focusIndex() >= opIndex && this.focusIndex() <= opIndex + num - 1) {
72 this.focusIndex(this.focusIndex() - 1);
73 } else if (this.focusIndex() > opIndex + num - 1) {
74 this.focusIndex(this.focusIndex() - num);
75 }
76 }
77 }
78};
79
80exports.setRowFocus = setRowFocus;
81exports.setRowUnFocus = setRowUnFocus;
82exports.updateFocusIndex = updateFocusIndex;
\No newline at end of file