").dxTreeView({
dataSource: dropDown.component.option("dataSource"),
dataStructure: "plain",
selectionMode: this.selectionMode,
showCheckBoxesMode: "normal",
searchEnabled: true,
selectByClick: true,
selectNodesRecursive: this.selectRecursive,
keyExpr: this.valueExpr,
displayExpr: this.displayExpr,
parentIdExpr: this.parentIdExpr,
onContentReady: () => this.syncTreeViewSelection(dropDown.component.option("value")),
onItemSelectionChanged: (tree) => {
let nodeKeys = this.getSelectedNodes(tree.component.getNodes());
dropDown.component.option("value", nodeKeys);
this.onChange(this.selectionMode == "single" ? nodeKeys[0] : nodeKeys);
}
});
this.treeView = $treeView.dxTreeView("instance");
return $treeView;
}
getGridView(dropDown) {
let value = dropDown.component.option("value");
let $dataGrid = this.jQuery("
").dxDataGrid({
height: "100%",
dataSource: dropDown.component.option("dataSource"),
columns: this.columns,
hoverStateEnabled: true,
paging: { enabled: true, pageSize: 10 },
filterRow: { visible: true },
scrolling: { mode: "infinite" },
selection: { mode: this.selectionMode },
selectedRowKeys: this.selectionMode == "single" ? [value] : value,
onSelectionChanged: (selectedItems) => {
let keys = selectedItems.selectedRowKeys;
let hasSelection = keys.length;
if (this.selectionMode == "single") dropDown.component.option("value", hasSelection ? keys[0] : null);
else dropDown.component.option("value", keys);
this.onChange(this.selectionMode == "single" ? keys[0] : keys);
}
});
this.gridView = $dataGrid.dxDataGrid("instance");
return $dataGrid;
}
syncTreeViewSelection(value) {
if (!this.treeView) return;
if (value && value.length) {
if (this.selectionMode == "single") this.treeView.selectItem(value);
else {
if (typeof value == "string") JSON.parse(value).forEach(el => { this.treeView.selectItem(el) });
else value.forEach(el => { this.treeView.selectItem(el) });
}
}
else this.treeView.unselectAll();
};
getSelectedNodes(nodes) {
var result = [];
for (let item of nodes) {
if (item.selected) result.push(item.key);
if (item.items.length) result = result.concat(this.getSelectedNodes(item.items));
}
return result;
};
}