UNPKG

kero

Version:
78 lines (72 loc) 1.97 kB
/** * Module : kero dataTable rowFocus * Author : liuyk(liuyk@yonyou.com) * Date : 2016-08-08 09:59:01 */ import {isNumber} from 'neoui-sparrow/js/util'; /** * 设置焦点行 * @param {Object} index 行对象或者行index * @param quiet 不触发事件 * @param force 当index行与已focus的行相等时,仍然触发事件 */ const setRowFocus = function (index, quiet, force) { var rowId = null if (index instanceof Row) { index = this.getIndexByRowId(index.rowId) rowId = index.rowId } if (index === -1 || (index === this.focusIndex() && !force)) { return; } this.focusIndex(index) if (quiet) { return; } this.currentRowChange(-this.currentRowChange()) if (!rowId) { rowId = this.getRow(index).rowId } this.trigger(DataTable.ON_ROW_FOCUS, { index: index, rowId: rowId }) this.updateCurrIndex(); } /** * 焦点行反选 */ const setRowUnFocus = function () { this.currentRowChange(-this.currentRowChange()) var indx = this.focusIndex(), rowId = null; if (indx !== -1) { rowId = this.getRow(indx).rowId } this.trigger(DataTable.ON_ROW_UNFOCUS, { index: indx, rowId: rowId }) this.focusIndex(-1) this.updateCurrIndex(); } const updateFocusIndex = function (opIndex, opType, num) { if (!isNumber(num)) { num = 1 } if (opIndex <= this.focusIndex() && this.focusIndex() != -1) { if (opType === '+') { this.focusIndex(this.focusIndex() + num) } else if (opType === '-') { if (this.focusIndex() >= opIndex && this.focusIndex() <= opIndex + num - 1) { this.focusIndex(this.focusIndex() - 1) } else if (this.focusIndex() > opIndex + num - 1) { this.focusIndex(this.focusIndex() - num) } } } } export { setRowFocus, setRowUnFocus, updateFocusIndex }