Posted 14 September 2017, 2:20 am EST
Hello Murray
By default, sorting a grid containing hierarchical data only sorts the top-level items. This is because the CollectionView does not really know anything about the data hierarchy, since the childItemsPath property belongs to the grid and not to the underlying CollectionView.
If you do want to sort some or all of the grid’s child items, you should handle the grid’s sortedColumn event to enumerate the items and perform the additional sorting on the child items yourself.
The code snippet below shows one way of doing this:
[js]// event handler for the sortedColumn event
$scope.sortedColumn = function (s, e) {
var view = s.collectionView;
// sort child items
if (view && s.childItemsPath) {
for (var i = 0; i < view.items.length; i++) {
sortItem(view.items[i], view, s.childItemsPath);
}
}
}
function sortItem(item, view, childItemsPath) {
var children = item[childItemsPath];
if (children && wijmo.isArray(children)) {
// sort array
children.sort(view._compareItems());
// sort child arrays
for (var i = 0; i < children.length; i++) {
sortItem(children[i], view, childItemsPath);
}
}
}[/js]
I hope this helps. Please let me know if you need any additional details OK?
PS: I have heard this question a couple of times, so I added this code to the FlexGridIntro sample where everyone can get it easily. That will be live in our next update.