UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

195 lines (194 loc) • 7.5 kB
/** * DevExtreme (esm/__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/ */ import { equalByValue } from "../../../../core/utils/common"; import { Deferred } from "../../../../core/utils/deferred"; import { extend } from "../../../../core/utils/extend"; import { DataController, dataControllerModule } from "../../../grids/grid_core/data_controller/data_controller"; import treeListCore from "../core"; const getNodeLevel = node => { let level = -1; let current = node; while (current.parent) { if (current.visible) { level += 1 } current = current.parent } return level }; export class TreeListDataController extends 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 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 Deferred().resolve() } collapseRow(key) { if (this.isRowExpanded(key)) { return this.changeRowExpand(key) } return 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 && !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) } } treeListCore.registerModule("data", { defaultOptions() { var _dataControllerModule; return extend({}, null === (_dataControllerModule = dataControllerModule.defaultOptions) || void 0 === _dataControllerModule ? void 0 : _dataControllerModule.call(dataControllerModule), { itemsExpr: "items", parentIdExpr: "parentId", rootValue: 0, dataStructure: "plain", expandedRowKeys: [], filterMode: "withAncestors", expandNodesOnFiltering: true, autoExpandAll: false, maxFilterLengthInRequest: 1500, paging: { enabled: false } }) }, controllers: { data: TreeListDataController } });