I have a 2 level tree.
1) When the tree opens the 2nd level is collapsed. is it possible to open with everything expanded by default?
2) How can I change the formatting of the 1st level parent items
3) How can I prevent the user from selecting a 1st level parent item and only allow the selecting of children items
4) How can I change the filtering to a custom filtering that I would write. Specifically if the person typed in a word that matched the 1st level it would show the first level item and all of it's children.
|
export class AppComponent {
public hierarchicalData: Object[] = [
{
id: '01',
name: 'Local Disk (C:)',
expanded: true,
subChild: [
{
id: '01-01',
name: 'Program Files',
expanded: true,
subChild: [
{ id: '01-01-01', name: 'Windows NT' },
],
},
{
id: '01-02',
name: 'Users',
expanded: true,
subChild: [
{ id: '01-02-01', name: 'Smith' },
],
},
},
];
public fields: Object = {
dataSource: this.hierarchicalData,
value: 'id',
text: 'name',
child: 'subChild',
expanded: 'expanded',
};
} |
|
app.component.css
.mytree .e-level-1 > .e-text-content .e-list-text {
font-style: italic;
}
-----------------------------------------------------------------------
app.component.html
<ejs-dropdowntree cssClass="mytree" [fields]="fields"></ejs-dropdowntree> |
Hi Shalini,
These all work great, the one area of confusion I have is how to use the filtering event to change the dropdown options.
I'm not quite sure what field to change and what it needs to be updated to. Am I updating fields in the event itself?
-Zack
Thanks for the update Indhumathy!
|
filtering(args) {
let _text = args.text;
this.isFilter = true;
args.preventDefaultAction = true;
let predicats = [],
_array = [],
_filter = [];
if (_text == '') {
args.fields.dataSource = this.filterData;
} else {
let predicate = new Predicate('name', 'startswith', _text, true);
let filteredList = new DataManager(this.filterData).executeLocal(
new Query().where(predicate)
);
for (let j = 0; j < filteredList.length; j++) {
_filter.push(filteredList[j]['id']);
let filters = this.getFilterItems(filteredList[j], this.filterData);
for (let i = 0; i < filters.length; i++) {
if (_array.indexOf(filters[i]) == -1 && filters[i] != null) {
_array.push(filters[i]);
if (filteredList[j].pid == undefined) {
predicats.push(new Predicate('pid', 'equal', filters[i], false));
}
predicats.push(new Predicate('id', 'equal', filters[i], false));
}
}
}
if (predicats.length == 0) {
args.fields.dataSource = [];
} else {
let query = new Query().where(Predicate.or(predicats));
let newList = new DataManager(this.filterData).executeLocal(query);
args.fields.dataSource = newList;
}
}
}
//Find the Parent Nodes for corresponding childs and all childs for searched parent.
public getFilterItems(fList, list) {
let nodes = [];
nodes.push(fList['id']);
let query2 = new Query().where('id', 'equal', fList['pid'], false);
let fList1 = new DataManager(list).executeLocal(query2);
if (fList1.length != 0) {
let pNode = this.getFilterItems(fList1[0], list);
for (let i = 0; i < pNode.length; i++) {
if (nodes.indexOf(pNode[i]) == -1 && pNode[i] != null)
nodes.push(pNode[i]);
}
return nodes;
} else {
let predicate = new Predicate('pid', 'equal', fList.id, false);
let filteredList = new DataManager(this.filterData).executeLocal(
new Query().where(predicate)
);
for (let i = 0; i < filteredList.length; i++) {
nodes.push(filteredList[i]);
}
}
return nodes;
} |