我正在寻找一种方法,将数据分组按月和按月分组......两个级别的分组。 现在,我可以将我的数据分组多年......
有人可以帮我吗?
我的模特:
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
// 'name',
// 'email',
'phone' ]});
我的数据:
var userStore = Ext.create('Ext.data.Store', {
model: 'User',
data: [
{ year: '2015', month : 'march', phone: '555-111-1224' },
{ year: '2015', month : 'april', phone: '555-222-1234' },
{ year: '2014', month : 'march', phone: '555-222-1244' },
{ year: '2014', month : 'april', phone: '555-222-1254' }
],
groupField: 'year'});
网格:
Ext.application({
name : 'MyApp',
launch : function() {
Ext.create('Ext.grid.Panel', {
renderTo: Ext.getBody(),
features: [{ ftype: 'grouping' }],
store: userStore,
width: 250,
height: 300,
title: 'Application Users',
columns: [
{
text: 'Phone Number',
flex: 1,
dataIndex: 'phone',
sortable: false,
hideable: false
}
]
});
}});
提前thx!
迈厄斯
答案 0 :(得分:1)
在商店中,尝试使用grouper配置而不是groupField。它将为您提供更灵活的数据分组方式。
以下是您的方案的示例:
var userStore = Ext.create('Ext.data.Store', {
model: 'User',
data: [
{ year: '2015', month : 'march', phone: '555-111-1224' },
{ year: '2015', month : 'april', phone: '555-222-1234' },
{ year: '2014', month : 'march', phone: '555-222-1244' },
{ year: '2014', month : 'april', phone: '555-222-1254' }
],
grouper: {
groupFn: function(item) {
return 'Month: ' + item.get('month') + ', Year: ' + item.get('year');
}
}
);
请参阅https://fiddle.sencha.com/#fiddle/jh9以了解相关信息。