分组表格和普通表格的主要区别在于store数据源定义,和grid的view配置项。
1、定义数据源,注意其中的read配置项的值json在之前已经定义,比较简单,这里就不写出来了。其中groupField是默认分组字段(表格中对应的列),groupDir是分组字段排列顺序。
var listStore = new Ext.data.GroupingStore( { url : "seniorTitleAction!findCommunicationDiscuss.action", reader : json, //sortInfo:{field:'threeYearDuring',direction: 'DESC'}, groupField: "threeYearDuring", groupDir : "DESC"// 分组字段将序排列,默认为升序 });2、然后在表格的定义中添加配置项view view: new Ext.grid.GroupingView({ groupByText: "根据本列分组", showGroupsText: "显示分组栏", forceFit: true, //hideGroupedColumn : true, // 隐藏分组列 groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "个记录" : "个记录"]})' }),分组列表结果如下图: