gloryBlade
gloryBlade

Reputation: 62

extjs4 grid grouped with function

Ext.define('record.SecurityCase', {
            extend : 'Ext.data.Model',
            fields : [{
                        name : 'id',
                        type : 'string',
                        persist : false
                    }, {
                        name : 'takeplaceTime',
                        type : 'date',
                        persist : true
                    },  {
                        name : 'brief',
                        type : 'string',
                        persist : true
                    }],
                    groupField: 'takeplaceTime' 
});

A grid with store used model above.And I want it to be grouped with 'takeplaceTime'.for example:

obj.takeplaceTime='2013-10-01';obj2.takeplaceTime='2013-04-01';obj3.takeplaceTime='2013-12-01';obj4.takeplaceTime='2012-12-01';

obj;obj2;obj3 are one group as its year is 2013. obj4 will be another ,year 2012.

Is there a groupRenderFunction to handle this?

Upvotes: 1

Views: 206

Answers (1)

Krzysztof
Krzysztof

Reputation: 16130

You can define calculated property in Model for grouping. Example:

Ext.define('Model1', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'name',  type: 'string'},
        {name: 'seniority',  type: 'string'},
        {name: 'department',  type: 'string'},
        {name: 'group', type: 'string', convert: function(value, record) {
            return record.get('name').substr(0, 1); // first letter of name
        } }
    ]
});

Working sample in Ext JS 4.2: http://jsfiddle.net/BmVeg/1/

Upvotes: 2

Related Questions