devextreme
Version:
HTML5 JavaScript Component Suite for Responsive Web Development
117 lines (115 loc) • 5.05 kB
JavaScript
/**
* DevExtreme (cjs/__internal/grids/tree_list/module_focus.js)
* Version: 22.1.9
* Build date: Tue Apr 18 2023
*
* Copyright (c) 2012 - 2023 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
;
var __importDefault = this && this.__importDefault || function(mod) {
return mod && mod.__esModule ? mod : {
default: mod
}
};
Object.defineProperty(exports, "__esModule", {
value: true
});
var extend_1 = require("../../../core/utils/extend");
var deferred_1 = require("../../../core/utils/deferred");
var ui_grid_core_focus_1 = require("../../../ui/grid_core/ui.grid_core.focus");
var module_core_1 = __importDefault(require("./module_core"));
function findIndex(items, callback) {
var result = -1;
items.forEach((function(node, index) {
if (callback(node)) {
result = index
}
}));
return result
}
module_core_1.default.registerModule("focus", extend_1.extend(true, {}, ui_grid_core_focus_1.focusModule, {
extenders: {
controllers: {
data: {
changeRowExpand: function(key) {
if (this.option("focusedRowEnabled") && this.isRowExpanded(key)) {
if (this._isFocusedRowInside(key)) {
this.option("focusedRowKey", key)
}
}
return this.callBase.apply(this, arguments)
},
_isFocusedRowInside: function(parentKey) {
var focusedRowKey = this.option("focusedRowKey");
var rowIndex = this.getRowIndexByKey(focusedRowKey);
var focusedRow = rowIndex >= 0 && this.getVisibleRows()[rowIndex];
var parent = focusedRow && focusedRow.node.parent;
while (parent) {
if (parent.key === parentKey) {
return true
}
parent = parent.parent
}
return false
},
getParentKey: function(key) {
var dataSource = this._dataSource;
var node = this.getNodeByKey(key);
var d = new deferred_1.Deferred;
if (node) {
d.resolve(node.parent ? node.parent.key : void 0)
} else {
dataSource.load({
filter: [dataSource.getKeyExpr(), "=", key]
}).done((function(items) {
var parentData = items[0];
if (parentData) {
d.resolve(dataSource.parentKeyOf(parentData))
} else {
d.reject()
}
})).fail(d.reject)
}
return d.promise()
},
expandAscendants: function(key) {
var that = this;
var dataSource = that._dataSource;
var d = new deferred_1.Deferred;
that.getParentKey(key).done((function(parentKey) {
if (dataSource && void 0 !== parentKey && parentKey !== that.option("rootValue")) {
dataSource._isNodesInitializing = true;
that.expandRow(parentKey);
dataSource._isNodesInitializing = false;
that.expandAscendants(parentKey).done(d.resolve).fail(d.reject)
} else {
d.resolve()
}
})).fail(d.reject);
return d.promise()
},
getPageIndexByKey: function(key) {
var that = this;
var dataSource = that._dataSource;
var d = new deferred_1.Deferred;
that.expandAscendants(key).done((function() {
dataSource.load({
parentIds: []
}).done((function(nodes) {
var offset = findIndex(nodes, (function(node) {
return that.keyOf(node.data) === key
}));
var pageIndex = -1;
if (offset >= 0) {
pageIndex = Math.floor(offset / that.pageSize())
}
d.resolve(pageIndex)
})).fail(d.reject)
})).fail(d.reject);
return d.promise()
}
}
}
}
}));