PDA

View Full Version : GroupHeaderTpl issue



kathy_s
14 Mar 2012, 7:42 AM
Hi,

I have the following grouping feature configured in my grid:

var groupingFeature = Ext.create('Ext.grid.feature.Grouping',{
groupHeaderTpl: 'Group : {name} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})',
enableGroupingMenu: true
});
Its output is :
Group:nameOfMyGroup (25 Items)
even if the group contains more than 25 items. This is normal, because 25 is my pagesize and only the data for the currentpage is loaded.
So now I am looking for a solution to put the correct number of items in the group headers.

I will have to adjust my restservice so that it returns the total number of items for each group.
And I will have to find a way to put that number in the group header.
This is where I need some help.

I guess I have to read the number of items from the responsetext in the callback of the load call of the store.
But how do I get that info in the group header?

kathy_s
15 Mar 2012, 12:28 AM
The available parameters in the values object of the groupHeaderTpl are: fullWidth, name, rows.length, viewId.
Is there a way to make an extra parameter available?

kathy_s
15 Mar 2012, 1:06 PM
No tips?
I can't imagine I'm the only one facing this problem...

Erikvip
15 Mar 2012, 6:49 PM
Well this is more of a workaround, but - how about making a secondary field, grouped_name, or something, which CONCAT's the name and count together, then group on it?


So, for example, your current column name is 'name'


SELECT
name,
CONCAT(name, ' ', ( SELECT count(*) FROM ... ) ) AS grouped_name


Then use the 'grouped_name' column as your group field, but hide the column so it's not visible in the grid.

kathy_s
16 Mar 2012, 12:10 AM
Thanks a lot for the answer!
It's a good workaround if you have fixed grouping on a certain field.
But in my case it's not easy to implement, since the users can group on any field (by clicking the header -> 'Group By This Field').

So I guess I will have to do something like
store.groupField = 'grouped_name'
in the callback of the load?