Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export interface TreeViewBaseProperties extends Properties<TreeViewNode>, Omit<
> {
deferRendering?: boolean;

allowSelect?: boolean | ((e: { component: TreeViewBase; item: ItemData }) => boolean);

_supportItemUrl?: boolean;
}

Expand Down Expand Up @@ -256,6 +258,7 @@ class TreeViewBase extends HierarchicalCollectionWidget<TreeViewBaseProperties,
_getDefaultOptions(): TreeViewBaseProperties {
const defaultOptions = {
...super._getDefaultOptions(),
allowSelect: true,
animationEnabled: true,
dataStructure: 'tree',
deferRendering: true,
Expand Down Expand Up @@ -1549,6 +1552,10 @@ class TreeViewBase extends HierarchicalCollectionWidget<TreeViewBaseProperties,
}

_renderCheckBox($node: dxElementWrapper, node: TreeViewNode | null): void {
if (!this._isItemSelectable(node)) {
return;
}

const $checkbox = $('<div>').appendTo($node);

this._createComponent<CheckBox, CheckBoxProperties>($checkbox, CheckBox, {
Expand Down Expand Up @@ -1581,6 +1588,28 @@ class TreeViewBase extends HierarchicalCollectionWidget<TreeViewBaseProperties,
}
}

_isItemSelectable(node: TreeViewNode | null): boolean {
if (!node) {
return true;
}

const { allowSelect } = this.option();

if (typeof allowSelect === 'boolean') {
return allowSelect;
}

if (isFunction(allowSelect)) {
const result = allowSelect({
component: this,
item: node.internalFields.item,
});
return Boolean(result);
}

return true;
}

_itemOptionChanged(item: Item, property: keyof Item, value: unknown): void {
const node = this._dataAdapter.getNodeByItem(item);
const { disabledExpr } = this.option();
Expand Down Expand Up @@ -1670,6 +1699,10 @@ class TreeViewBase extends HierarchicalCollectionWidget<TreeViewBaseProperties,
return false;
}

if (!this._isItemSelectable(node)) {
return false;
}

if (node.internalFields.selected === value) {
return true;
}
Expand Down Expand Up @@ -2211,7 +2244,10 @@ class TreeViewBase extends HierarchicalCollectionWidget<TreeViewBaseProperties,
}

getSelectedNodeKeys(): ItemKey[] {
return this._dataAdapter.getSelectedNodesKeys();
return this._dataAdapter.getSelectedNodesKeys().filter((key: ItemKey) => {
const node = this._dataAdapter.getNodeByKey(key) as TreeViewNode;
return this._isItemSelectable(node);
});
}

selectAll(): void {
Expand Down
Loading