The group And Sort is a transcluding directive to will group an array of objects into categories as deep as you like. After grouping your objects into categories, you may sort your categories at every level and finally, sort your items.
Objects may not be fully categorised, if some of the objects do not have as many sub-categories as other objects, they simply remain at the group into which they were categorised.
Grouping and sorting is not mandatory. You can group item and skip sort or skip grouping and justsort items. (however, if you do not group - you cannot sort by categories).
Grouping and sorting of categories and items is acheived by calling your assigned grouping and sorting functions as described bellow.The group And Sort directive does nothing until data is requested by its transcluded directive. You call the directive's 'data' function in order to retreive the groupd and sorted objects which are encapsulated in a convinient-to-retreive data structure.
groupingFunction = function(object, level) {
your grouping logic ...
return categoryName or return null
}
categorySortingFunction = function(categoryName1, categoryName2) {
your sorting logic ...
return -1 // category1 appears before category2
or return 0 // either one may appear before the other
or return 1 // category2 appears before category1
}
itemSortingFunction=function(obj1, obj2) {
your sorting logic ...
return -1 // obj1 appears before obj2
or return 0 // either one may appear before the other
or return 1 // obj2 appears before obj1
}
[
{
category: categoryName,
isLeaf: true / false
objects: [ array of objects ]
},
]
The value of the top-most category will always be null as this is the root of the catgories tree.
If no grouping is requested, then all the objects are present in the 'objects' array. (the objects may still be sorted, if a sort-items function was provided to the directive.)
If grouping is requested, then each category will be manifested in the 'object' array as an object whose properties are 'category' 'isLeaf' and 'objects' as the object depicted above. At each level objects who are cannot be further categorised (as the rest) are collected into an array which is the last element of the objects array.
If the value of property 'isLeaf' equals 'true' then you know that there are no further sub-categories in this group and that the objects array contains (fully categorised) plain objects only.
If all your objects are fully categorised, then you need not worry about not fully categorised items. All your objects will like the one above, and all your objects will be at leafs.