2
votes

On the following grid grouping example. How can I display The first group as (0 Countries), if no data is returned for the first record.

Currently, if there are no records, the first group does not appear

enter image description here

What I need to do is, show the first group with (0) count and not just make it disappear. Is there way to still show up the group header, even if there is no data, like a default header or something? Any ideas? I need to do this for all the 4 headers

Update

Ext.require(['Ext.data.*', 'Ext.grid.*']);
Ext.onReady(function() {
Ext.define('Country', {
    extend: 'Ext.data.Model',
    fields: ['name']
});

var Country = Ext.create('Ext.data.Store', {
    storeId: 'country',
    model: 'Country',
    groupField: 'countryName',
    proxy: {
            type: 'ajax',
            scope: this,
            url: 'myExtjsApp/ExtjsGetRecord',
            reader: {
                type: 'json',
                root: 'data'
            }
        }
});

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

var grid = Ext.create('Ext.grid.Panel', {
    renderTo: Ext.getBody(),
    collapsible: true,
    iconCls: 'icon-grid',
    frame: true,
    store: Country,
    width: 600,
    height: 400,
    title: 'Country',
    features: [groupingFeature],
    columns: [{
        text: 'Country',
        flex: 1,
        dataIndex: 'name'
    }]
});
});
1
Can you add your json data feed also. (or part of it) - Dawesi
I see you duped this answer here to get your code: stackoverflow.com/questions/7521567/… - Dawesi

1 Answers

0
votes

side topic:

for your header template you can also use plural format function instead of just adding 's': (which ironically this does if you don't pass singular and plural arguments)... just a thought.

http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.util.Format-method-plural