Reputation: 6466
I need to change groupHeaderTpl upon to the groupingField value. In my case, I group through a boolean field. How can I do this?
groupHeaderTpl: '{name}=="true" ? Shared : Your own'
groupHeaderTpl: '[{name}=="true" ? Shared : Your own]'
Upvotes: 0
Views: 6452
Reputation: 11
You might like to try the following:
groupHeaderTpl: '{[values.groupValue ? "Shared" : "Your own"]}'
This works for me with Ext JS 4.2 (although I haven't verified it with 4.1, the documentation also describes groupValue).
HTH
Upvotes: 1
Reputation: 156
If the below answer doesn't help you, here's a technique you could use to debug:
Introduce a debugging function "objectToString" in your page:
function ObjectToString(object) {
var string;
var name;
for (name in object) {
if (typeof object[name] !== 'function') {
string += "{\"" + name + "\": \"" + object[name] + "\"}<br />";
}
}
return string;
}
Then, use this function to dump out the attributes in the values.rows[0] object so you can see if the columns / values you want are available for the test:
var groupingFeature = Ext.create('Ext.grid.feature.Grouping',{
groupHeaderTpl: 'Debug: {[ObjectToString( values.rows[0] ) ]}',
hideGroupedHeader: true
});
When this is used to debug the example below, you can get this debugging output:
So, from this you can see that by setting the "id" property of the column I'm grouping on, that makes the column name available in the values.rows array so I can test its value.
Again, hope this technique and the below original sample helps.
==== Original Example Below Before Debugging Code ====
Here's a sample modified slightly from the Sencha grid grouping example. (See sencha site, grid grouping example).
var groupingFeature = Ext.create('Ext.grid.feature.Grouping',{
groupHeaderTpl: 'Cuisine: {[ values.rows[0].cuisine == "American" ? "North American" : values.rows[0].cuisine ]}',
hideGroupedHeader: true
});
var grid = Ext.create('Ext.grid.Panel', {
renderTo: Ext.getBody(),
collapsible: true,
iconCls: 'icon-grid',
frame: true,
store: Restaurants,
width: 600,
height: 400,
title: 'Restaurants',
resizable: true,
features: [groupingFeature],
columns: [{
text: 'Name',
flex: 1,
dataIndex: 'name'
},{
text: 'Cuisine',
id: 'cuisine', // NOTE: you must assign an id here
flex: 1,
dataIndex: 'cuisine'
}],
fbar : ['->', {
text:'Clear Grouping',
iconCls: 'icon-clear-group',
handler : function(){
groupingFeature.disable();
}
}]
});
The things to keep in mind are:
I hope that helps you.
Upvotes: 3