对于分组表格,要想获取到分组的某一个分组
var courseStore=Ext.create('Ext.data.Store',{ storeId:'courseStore', fields:['Name','Type','Credit','Period','Teacher'], autoLoad:{start:0,limit:itemsPerPage}, pageSize: itemsPerPage, groupField:'Type', // data:{'items':[ // {'Name':'SQL深入详解','Type':'必修','Credit':'3','Period':'6周','Teacher':'zhang'}, // {'Name':'SQL深入详解','Type':'必修','Credit':'3','Period':'6周','Teacher':'zhang'}, // ]}, proxy:{ type:'ajax', url:'json/course.json', reader:{ type:'json', root:'items', totalProperty:'counts' } } }); var sm=Ext.create("Ext.selection.CheckboxModel",{ mode:'MULTI', checkOnly:true, renderer:function(value,metaData,record,rowIndex,colIndex,store,view){ var type=record.get("Type"); if(type=="必修"){ return ''; }else{ return '<div class="' + Ext.baseCSSPrefix + 'grid-row-checker"> </div>'; } } }); var courseGrid=Ext.create('Ext.grid.Panel',{ store:courseStore, selModel:sm, multiSelect:true, viewConfig:{ forceFit:true, scrollOffset: 0 }, features:[ Ext.create("Ext.grid.feature.Grouping",{ groupHeaderTpl:'课程类型:{name}(共有{rows.length}门)', startCollapsed:false }) ], columns:[ {header:'课程名',dataIndex:'Name',flex:2}, {header:'类型',dataIndex:'Type'}, {header:'学分',dataIndex:'Credit'}, {header:'学时',dataIndex:'Period'}, {header:'代课老师',dataIndex:'Teacher'}, ], listeners:{ viewready:function(grid,eOpts){ var hd_checker =grid.getEl().select('.x-column-header-checkbox'); var hd = hd_checker.first(); if (hd_checker.hasCls('x-column-header-checkbox')) { hd_checker.removeCls('x-column-header-checkbox'); 0// 去掉全选框 } hd.destroy(); } } });Extjs4.x提供了getGroups,可以传递groupName,也就是store中配置的groupField的值
var myStore = Ext.create('Ext.data.Store', { groupField: 'color', groupDir : 'DESC' }); myStore.getGroups(); //returns: [ { name: 'yellow', children: [ //all records where the color field is 'yellow' ] }, { name: 'red', children: [ //all records where the color field is 'red' ] } ]
//确认选择的课 function selectCourseOk(){ var mustSelectCount;//必修个数,必须选择 var records=courseStore.getGroups("必修").children; //返回是model[] mustSelectCount=records.length; alert(mustSelectCount); courseGrid.getSelectionModel().selectRange(0,mustSelectCount-1,true); var recordes=courseGrid.getSelectionModel().getSelecion(); //返回Model[] }