扩展GridPanel,附带分页选中状态,实现快速构建一个功能齐全的Grid

使用简单的配置就可以实现 store, columns, selModel , pagingToolbar ,

最重要的一点是实现分页时可以保持前一页的选中状态,
 但是要遵守其中的一些规定,至于哪些规定呢,看下面的代码就知道啦!
 代码如下:

/*
* @class Ext.ux.grid.CollectGrid
* @version: 1.0
* @author: chengbao_zhu
*
* Example : Ext.onReady(function(){
var CM_JR_Record = [
{
dataIndex:"", //the ColumnModel options alse the JsonReader mapping (required)
header:"", //the ColumnModel options (required)
visiable: false, //my expands option to show the header or not (options)
type: date, //the type of this data (options)
...another options of ColumnModel
},{
dataIndex : '',
header : "",
width : 130
}];

var myGrid = new Ext.ux.grid.CollectGrid({
url : 'MyJsp.jsp', // the store load url (required)
CM_JR_Record: CM_JR_Record, //.....(required)
rowNumber:true, //true to add a Ext.grid.RowNumberer,defalut(true)
checkBox:true, //true to add a Ext.grid.CheckBoxSelectionModel,default(true)
pagingBar:true, //true to add a Ext.PagingToolBar,default(true)
pagingConfig:objcet, //config pagingToolBar if pagingBar is true
keepSelectedOnPaging: true, //true to FireEvent when you paging to keep the state of record selected
recordIds : new Array() , // store seleced ids when keepSelectedOnPaging is true
idColName :'stat_id', //the id column name

...another
width : 700,
height: 600,

title : 'This is My Grid' ,
renderTo: 'my_grid'
});

myGrid.store.load({params:{start:0,limit:myGrid.pagingConfig.pageSize}});
//myUxGrid.render();
myGrid.on('rowclick',function(grid,rowIndex,e){
alert(grid.getStore().getAt(rowIndex).data['stat_id']);
}
);
}
);
*/


Ext.namespace('Ext.ux.grid');

Ext.ux.grid.CollectGrid = Ext.extend(Ext.grid.GridPanel,{

/*
* true to keep the records selected when you paging
* @default(false)
* @type: boolean
*/
keepSelectedOnPaging: false,

/*
* the array to store the record id
* @type: array
*/
recordIds:new Array(),

/*
* set your id Column Name
* @default : this.CM_JR_Record[0].dataIndex
*/
idColName:'',

/*
* set this.store.load url;
* @type: string
*/
url: '',

/*
* show the rowNumber or not
* @type: boolean
* @default: true
*/
rowNumber : true,

/*
* set the grid sm,if checkBoxSelection=true,sm=CheckBoxSelectionModel
* else sm=RowSelectionModel,default to true;
* @type: boolean
*/
checkBox: true,

/*
* set the grid cm array;
* set the JsonReader record;
*
* format: [{name:'',header:'',visiable:'',...another cm options},{}],
* @name=dataIndex
* @visiable: set this record to the cm(grid header) default(true)
* @type: array (records)
*/
CM_JR_Record: null,

/*
* true to add a bottom paging bar
* @defalut: true
* @type: boolean
*/
pagingBar: true,

/*
* config paging bar if pagingBar set true
* @type: object
* @default: {pageSize: 20,store: this.store,displayInfo: true,
* displayMsg: '当前记录数: {0} - {1} 总记录数: {2}',
* emptyMsg: '<b>0</b> 条记录'}
*/
pagingConfig:{
pageSize: 20,
//store: this.store,
displayInfo: true,
displayMsg: '当前记录数: {0} - {1} 总记录数: {2}',
emptyMsg: '<b>0</b> 条记录'
},

viewConfig:{
forceFit: true
},

//private
initComponent: function(){
if(this.CM_JR_Record){
this.init_SM_CM_DS();
}
if(this.pagingBar){
this.init_PagingBar();
}
if(this.keepSelectedOnPaging){
this.init_OnPaging();
}
Ext.ux.grid.CollectGrid.superclass.initComponent.call(this);
},

/*
* init the grid use the config options
* @return: void
* @params: none
*/
init_SM_CM_DS: function(){
var gCm = new Array();
var gRecord = new Array();

if(this.rowNumber){
gCm[gCm.length]=new Ext.grid.RowNumberer();
}
if(this.checkBox){
var sm = new Ext.grid.CheckboxSelectionModel();
gCm[gCm.length] = sm;
this.selModel = sm;
}

for(var i=0;i<this.CM_JR_Record.length;i++)
{
var g = this.CM_JR_Record[i];
if(g.visiable || g.visiable=='undefined' || g.visiable==null){
gCm[gCm.length] = g;
}

gRecord[gRecord.length]={
name: g.dataIndex,
type: g.type || 'string'
}
}

//create grid columnModel
this.cm = new Ext.grid.ColumnModel(gCm);
this.cm.defaultSortable = true;

//create a jsonStore
this.store = new Ext.data.Store({

proxy: new Ext.data.HttpProxy({
url: this.url,
method: 'post'
}),
reader:new Ext.data.JsonReader({
totalProperty: 'totalProperty',
root: 'root'
},
Ext.data.Record.create(gRecord)
)

});


this.pagingConfig.store = this.store;

if(this.pagingBar){
this.store.load({params:{start:0,limit:this.pagingConfig.pageSize}});
}else{
this.store.load();
}

},

/*
* 创建并初始化paging bar
*/
init_PagingBar: function(){
var bbar = new Ext.PagingToolbar(this.pagingConfig);
this.bbar = bbar;
},

init_OnPaging: function(){

this.idColName = this.CM_JR_Record[0].dataIndex ;//默认第一列为ID列

this.selModel.on('rowdeselect',function(selMdl,rowIndex,rec ){


for(var i=0;i<this.recordIds.length;i++)
{
if(rec.data[this.idColName] == this.recordIds[i]){
this.recordIds.splice(i,1);
return;
}
}


},this);

this.selModel.on('rowselect',function(selMdl,rowIndex,rec){
if(this.hasElement(this.recordIds)){
for(var i=0;i<this.recordIds.length;i++){
if(rec.data[this.idColName] == this.recordIds[i]){
return;
}
}
}

this.recordIds.unshift(rec.data[this.idColName]);

},this);

this.store.on('load',function(st,recs){
if(this.hasElement(this.recordIds)){
st.each(function(rec){
Ext.each(this.recordIds,function(item,index,allItems){
if(rec.data[this.idColName] == item){
this.selModel.selectRecords([rec],true);
return false;
}
},this);
},this);
}
},this);

},

hasElement : function(recIds){
if(recIds.length > 0)
return true;
else
return false;
}

}
)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
辽B代驾管理系统对代驾订单管理、用户咨询管理、代驾订单评价管理、代驾订单投诉管理、字典管理、论坛管理、公告管理、新闻信息管理、司机管理、用户管理、管理员管理等进行集中化处理。经过前面自己查阅的网络知识,加上自己在学校课堂上学习的知识,决定开发系统选择小程序模式这种高效率的模式完成系统功能开发。这种模式让操作员基于浏览器的方式进行网站访问,采用的主流的Java语言这种面向对象的语言进行辽B代驾管理系统程序的开发,在数据库的选择上面,选择功能强大的Mysql数据库进行数据的存放操作。辽B代驾管理系统的开发让用户查看代驾订单信息变得容易,让管理员高效管理代驾订单信息。 辽B代驾管理系统具有管理员角色,用户角色,这几个操作权限。 辽B代驾管理系统针对管理员设置的功能有:添加并管理各种类型信息,管理用户账户信息,管理代驾订单信息,管理公告信息等内容。 辽B代驾管理系统针对用户设置的功能有:查看并修改个人信息,查看代驾订单信息,查看公告信息等内容。 辽B代驾管理系统针对管理员设置的功能有:添加并管理各种类型信息,管理用户账户信息,管理代驾订单信息,管理公告信息等内容。 辽B代驾管理系统针对用户设置的功能有:查看并修改个人信息,查看代驾订单信息,查看公告信息等内容。 系统登录功能是程序必不可少的功能,在登录页面必填的数据有两项,一项就是账号,另一项数据就是密码,当管理员正确填写并提交这二者数据之后,管理员就可以进入系统后台功能操作区。项目管理页面提供的功能操作有:查看代驾订单,删除代驾订单操作,新增代驾订单操作,修改代驾订单操作。公告信息管理页面提供的功能操作有:新增公告,修改公告,删除公告操作。公告类型管理页面显示所有公告类型,在此页面既可以让管理员添加新的公告信息类型,也能对已有的公告类型信息执行编辑更新,失效的公告类型信息也能让管理员快速删除。新闻管理页面,此页面提供给管理员的功能有:新增新闻,修改新闻,删除新闻。新闻类型管理页面,此页面提供给管理员的功能有:新增新闻类型,修改新闻类型,删除新闻类型。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值