简体   繁体   中英

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?

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM