PDA

View Full Version : Grouped grid won't show data name in group header



Intern
17 Apr 2012, 4:00 AM
Hi there,

I'm trying to create a grouped grid, like in this Sencha example (http://dev.sencha.com/deploy/ext-4.0.7-gpl/examples/grid/groupgrid.html).

But I can't manage to have the 'name' field displayed on the group header (American, Asian,... in the example). It just displays 'Cuisine :'

Is there something I should know about this part of code ? :


var groupingFeature = Ext.create('Ext.grid.feature.Grouping',{
groupHeaderTpl: 'Cuisine: {name} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})'
});

Putting the field name between braces isn't enough ?

scottmartin
17 Apr 2012, 5:13 AM
You would also need to update the getGroupString:



getGroupString: function(instance) {
return instance.get('cuisine') + '/' + instance.get('pricing') + '/' + instance.get('name')
},


Regards,
Scott.

Intern
17 Apr 2012, 6:31 AM
I don't see this function in the groupgrid.js file. Should I add it ? Where ?

I'm sorry if this is obvious but I'm really new to ExtJS.
Thanks for your answer :)

scottmartin
17 Apr 2012, 7:01 AM
Add this to your store:



var Restaurants = Ext.create('Ext.data.Store', {
storeId: 'restaraunts',
model: 'Restaurant',
sorters: ['category'],
groupField: 'category',
getGroupString: function(instance) {
return instance.get('cuisine') + '/' + instance.get('pricing')
},
..


Scott.

Intern
18 Apr 2012, 2:06 AM
Still doesn't work, I don't know what I'm doing wrong but obviously there is something...

scottmartin
18 Apr 2012, 5:01 AM
Can you post your code so we can have a look?

Regards,
Scott.

chramer
18 Apr 2012, 5:20 AM
Show us your store declaration!

Intern
18 Apr 2012, 5:42 AM
My mistake, I found the problem, I forgot to delete a line which was trying to define something else for the header.

But I still have a question. Now my header is "Group: 'the group title' ".
Is there a way to just have 'the group title' or to change the word Group for another one ?

chramer
18 Apr 2012, 5:56 AM
groupHeaderTpl: '{name}' //only the <group_title>
..
groupHeaderTpl: 'SOMETHINGELSE : {name}' //SOMETHINGELSE : <group_title >

Intern
18 Apr 2012, 6:28 AM
OOOOH I just understood something !
When you write {name} it's not because your grouping field is called 'name'. In the Sencha example there are two fields: name and cuisine so I thought that if my field is called 'sport' I should right {sport} in the groupHeaderTpl...
I have changed it to {name} and it works of course.

Sorry for wasting your time and thanks a lot, to both of you :)

chramer
18 Apr 2012, 7:35 AM
you're a genius! :D
good luck ;)