Hi, I wanted to ask if it’s expected that in a Tree with modelType: 'children', the sort/sortByProperty methods only sort the first level of nodes and not the children.
Announcement
Collapse
No announcement yet.
X
-
The whole tree is visibly sorted, and you can see here:
https://smartclient.com/smartclient/...childrenArrays
However, to get the sorted order, you have to look at getOpenList(), because we don't modify the children arrays directly.
-
Actually, employeeTree.data.sortByProperty("Name", true) does sort the TreeGrid in the sample.
However, I was expecting it to sort a Menu like this:
Code:var tree = isc.Tree.create({ modelType: "children", nameProperty: "Name", childrenProperty: "directReports", root: {EmployeeId: "1", directReports: [ {EmployeeId:"4", Name:"Charles Madigen", directReports: [ {EmployeeId:"188", Name:"Rogine Leger"}, {EmployeeId:"189", Name:"Gene Porter", directReports: [ {EmployeeId:"265", Name:"Olivier Doucet"}, {EmployeeId:"264", Name:"Cheryl Pearson"} ]} ]} ]} }); tree.sortByProperty("Name",true) isc.Menu.create({ ID: "menu", autoDraw: false, showShadow: true, shadowDepth: 10, data: tree }); var menuButton = isc.MenuButton.create({ ID: "menuButton", autoDraw: false, title: "File", width: 100, menu: menu }); isc.HStack.create({ width: "100%", members: [menuButton] });
Comment
-
As mentioned above, the children arrays are not re-ordered, instead, the Tree makes available the getOpenList() API that view components can use to present the sorted (and filtered) tree.
When you consider filtering, you realize it has to be done this way because otherwise we would need to reach in and remove elements from the children arrays.
So, getOpenList() works well for TreeGrid and you have sorting and filtering.
However, when you have a Menu with submenus, that is actually several separate Menu components, each Menu is allowed to have separate settings; you can even mix databound menus with hardcoded menus, and so forth.
So there isn't a way for them to use getOpenList() and present a single, filtered and sorted view across multiple submenus.
So, some options:
1) you could just use a TreeGrid as your menu (or a NavPanel, which contains such a tree)
2) you could use the getOpenList() API to rebuild your tree based on the sorted order - that's a fairly simple algorithm because you just iterate down the openList, adding children, and when you hit a folder, you recurse
Comment
Comment