cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Sort & Group - SAP UI Table - Group Header Issue

0 Kudos
2,388

Hallo,

I am working on a use case where I have to group the column entries based on a group category and sort the entries with in the group.

I am using sap.ui.Table control. Since, the column group is based on custom criteria I have implemented custom sort with grouping on the data binding using model sorter.

I have followed the following post as an example and adapted it to my case -

https://blogs.sap.com/2013/11/29/custom-sorter-and-grouper/

Here is my implementation:

var mGroupInfo = {

I: { order: 1, text: "Incidents" },

N: { order: 2, text: "Notifications" }

}

var fGroup = function(value) { // Must group the values starts with 9 and 1

return utilities.startsWith(value,"9") ? "I" : "N";

}

var fnGrouper = function(oContext) {

var value = oContext.getProperty(sColBindingPath);

var group = fGroup(value);

return {

key: group,

text: mGroupInfo[group].text

};

};

var oSorter = new sap.ui.model.Sorter(sColBindingPath,false,fnGrouper);

oSorter.fnCompare = function(a,b) {

var agroup = mGroupInfo[fGroup(a)].order;

var bgroup = mGroupInfo[fGroup(b)].order;

if (agroup < bgroup) return -1;

if (agroup > bgroup) return 1;

// Sort with in the group if (a < b) return -1;

if (a == b) return 0; if (a > b) return 1;

};

this.getId("workorder-table").getBinding("rows").sort(oSorter);

Result:

The entries are sorted correctly according to the group but I do not see the group header text (like "Incidents" for entries start with 9 and "Notifications" for entries start with 1). For this to happen, the grouper function should go through. But while debugging I see that this function is not invoked at all.

Could some one please provide some hints what am missing here !! Thank you.

View Entire Topic
Sharathmg
Active Contributor
0 Kudos
0 Kudos

Hello Sharath,

Thanks for your effort. I have referred these links already.

But this will not help.