devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
198 lines (196 loc) • 7.87 kB
JavaScript
/**
* DevExtreme (cjs/__internal/grids/tree_list/data_controller/data_controller.js)
* Version: 26.1.6
* Build date: Fri Oct 16 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TreeListDataController = void 0;
var _common = require("../../../../core/utils/common");
var _deferred = require("../../../../core/utils/deferred");
var _extend = require("../../../../core/utils/extend");
var _data_controller = require("../../../grids/grid_core/data_controller/data_controller");
var _core = _interopRequireDefault(require("../core"));
function _interopRequireDefault(e) {
return e && e.__esModule ? e : {
default: e
}
}
const getNodeLevel = node => {
let level = -1;
let current = node;
while (current.parent) {
if (current.visible) {
level += 1
}
current = current.parent
}
return level
};
class TreeListDataController extends _data_controller.DataController {
_generateDataItem(node, options) {
return {
rowType: "data",
node: node,
key: node.key,
data: node.data,
isExpanded: this.isRowExpanded(node.key, options),
level: getNodeLevel(node)
}
}
_loadOnOptionChange() {
var _this$dataSourceContr;
null === (_this$dataSourceContr = this.dataSourceController.getAdapter()) || void 0 === _this$dataSourceContr || _this$dataSourceContr.load()
}
isSameRowState(item1, item2) {
if (item1.isSelected !== item2.isSelected) {
return false
}
if (item1.node && item2.node && item1.node.hasChildren !== item2.node.hasChildren) {
return false
}
if (item1.level !== item2.level || item1.isExpanded !== item2.isExpanded) {
return false
}
return super.isSameRowState(item1, item2)
}
_isCellChanged(oldRow, newRow, visibleRowIndex, columnIndex, isLiveUpdate) {
const firstDataColumnIndex = this._columnsController.getFirstDataColumnIndex();
if (columnIndex === firstDataColumnIndex && oldRow.isSelected !== newRow.isSelected) {
return true
}
return super._isCellChanged(oldRow, newRow, visibleRowIndex, columnIndex, isLiveUpdate)
}
init() {
this.createAction("onRowExpanding");
this.createAction("onRowExpanded");
this.createAction("onRowCollapsing");
this.createAction("onRowCollapsed");
super.init()
}
publicMethods() {
return super.publicMethods().concat(["expandRow", "collapseRow", "isRowExpanded", "getRootNode", "getNodeByKey", "loadDescendants", "forEachNode"])
}
needUpdateDimensions(operationTypes) {
return super.needUpdateDimensions(operationTypes) || Boolean(null === operationTypes || void 0 === operationTypes ? void 0 : operationTypes.nodeExpanding)
}
changeRowExpand(key) {
const dataSourceAdapter = this.dataSourceController.getAdapter();
if (dataSourceAdapter) {
const args = {
key: key
};
const isExpanded = this.isRowExpanded(key);
this.executeAction(isExpanded ? "onRowCollapsing" : "onRowExpanding", args);
if (!args.cancel) {
return dataSourceAdapter.changeRowExpand(key).done(() => {
this.executeAction(isExpanded ? "onRowCollapsed" : "onRowExpanded", args)
})
}
}
return (0, _deferred.Deferred)().resolve()
}
isRowExpanded(key, cache) {
var _this$dataSourceContr2;
return null === (_this$dataSourceContr2 = this.dataSourceController.getAdapter()) || void 0 === _this$dataSourceContr2 ? void 0 : _this$dataSourceContr2.isRowExpanded(key, cache)
}
expandRow(key) {
if (!this.isRowExpanded(key)) {
return this.changeRowExpand(key)
}
return (0, _deferred.Deferred)().resolve()
}
collapseRow(key) {
if (this.isRowExpanded(key)) {
return this.changeRowExpand(key)
}
return (0, _deferred.Deferred)().resolve()
}
getRootNode() {
var _this$dataSourceContr3;
return null === (_this$dataSourceContr3 = this.dataSourceController.getAdapter()) || void 0 === _this$dataSourceContr3 ? void 0 : _this$dataSourceContr3.getRootNode()
}
optionChanged(args) {
switch (args.name) {
case "rootValue":
case "parentIdExpr":
case "itemsExpr":
case "filterMode":
case "expandNodesOnFiltering":
case "autoExpandAll":
case "hasItemsExpr":
case "dataStructure":
this._columnsController.reset();
this._items = [];
this.resetDataSource();
args.handled = true;
break;
case "expandedRowKeys":
case "onNodesInitialized": {
const dataSourceAdapter = this.dataSourceController.getAdapter();
const isReloadNeeded = dataSourceAdapter && !dataSourceAdapter._isNodesInitializing && !(0, _common.equalByValue)(args.value, args.previousValue);
if (isReloadNeeded) {
this._loadOnOptionChange()
}
args.handled = true;
break
}
case "maxFilterLengthInRequest":
args.handled = true;
break;
default:
super.optionChanged(args)
}
}
getNodeByKey(key) {
var _this$dataSourceContr4;
return null === (_this$dataSourceContr4 = this.dataSourceController.getAdapter()) || void 0 === _this$dataSourceContr4 ? void 0 : _this$dataSourceContr4.getNodeByKey(key)
}
getChildNodeKeys(parentKey) {
var _this$dataSourceContr5;
return null === (_this$dataSourceContr5 = this.dataSourceController.getAdapter()) || void 0 === _this$dataSourceContr5 ? void 0 : _this$dataSourceContr5.getChildNodeKeys(parentKey)
}
loadDescendants(keys, childrenOnly) {
var _this$dataSourceContr6;
return null === (_this$dataSourceContr6 = this.dataSourceController.getAdapter()) || void 0 === _this$dataSourceContr6 ? void 0 : _this$dataSourceContr6.loadDescendants(keys, childrenOnly)
}
forEachNode() {
this.dataSourceController.getAdapter().forEachNode(...arguments)
}
getAllDataRowKeys() {
var _this$dataSourceContr7;
const keys = [];
null === (_this$dataSourceContr7 = this.dataSourceController.getAdapter()) || void 0 === _this$dataSourceContr7 || _this$dataSourceContr7.forEachNode(node => {
keys.push(node.key)
});
return Promise.resolve(keys)
}
}
exports.TreeListDataController = TreeListDataController;
_core.default.registerModule("data", {
defaultOptions() {
var _dataControllerModule;
return (0, _extend.extend)({}, null === (_dataControllerModule = _data_controller.dataControllerModule.defaultOptions) || void 0 === _dataControllerModule ? void 0 : _dataControllerModule.call(_data_controller.dataControllerModule), {
itemsExpr: "items",
parentIdExpr: "parentId",
rootValue: 0,
dataStructure: "plain",
expandedRowKeys: [],
filterMode: "withAncestors",
expandNodesOnFiltering: true,
autoExpandAll: false,
maxFilterLengthInRequest: 1500,
paging: {
enabled: false
}
})
},
controllers: {
data: TreeListDataController
}
});