Ext.GridPanel 用法总结(一)—— Grid基本用法

Ext.GridPanel 用法总结(一)—— Grid基本用法

摘自:http://www.cnblogs.com/luluping/archive/2009/08/01/1536645.html

GridPanel类是基于基础列表接口具代表性的主要实现类。也是最常用的Ext组件之一。

一:首先定义grid的数据源

view plaincopy to clipboardprint?
 //初始化Ext状态管理器,在Cookie中记录用户的操作状态,如果不启用,象刷新时就不会保存当前的状态,而是重新加载                  
    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());   
    Ext.QuickTips.init();       //显示提示信息  
    var pageSize=10;//定义每页显示的行数  
  //定义数据字段   
 var fields = ["journal_id","journal_name","journal_organizer","journal_level","is_core"];  
//定义数据源     
 journal_store = new Ext.data.Store({  
        // 获取数据  
         proxy:new Ext.data.HttpProxy(  
           {  
                 url:"Data/SystemManage/Journal/JournalsInfo.aspx",//获取数据的后台地址  
                 method:"POST" 
           }),  
           //解析json  
           reader:new Ext.data.JsonReader(  
           {  
                fields:fields,  
                root:"data",  
                id:"roleId",  
                totalProperty:"totalCount"          //总的数据条数  
           })  
    });  
//根据参数加载数据  
 journal_store.load({params:{journal_name:journal_name,journal_organizer:journal_organizer,journal_level:journal_level,is_core:is_core,start:0,limit:pageSize}});

//初始化Ext状态管理器,在Cookie中记录用户的操作状态,如果不启用,象刷新时就不会保存当前的状态,而是重新加载               
    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
    Ext.QuickTips.init();       //显示提示信息
    var pageSize=10;//定义每页显示的行数
  //定义数据字段
 var fields = ["journal_id","journal_name","journal_organizer","journal_level","is_core"];
//定义数据源  
 journal_store = new Ext.data.Store({
  // 获取数据
   proxy:new Ext.data.HttpProxy(
           {
                 url:"Data/SystemManage/Journal/JournalsInfo.aspx",//获取数据的后台地址
                 method:"POST"
           }),
           //解析json
           reader:new Ext.data.JsonReader(
        {
       fields:fields,
    root:"data",
                id:"roleId",
                totalProperty:"totalCount"          //总的数据条数
           })
 });
//根据参数加载数据
 journal_store.load({params:{journal_name:journal_name,journal_organizer:journal_organizer,journal_level:journal_level,is_core:is_core,start:0,limit:pageSize}});

二:定义其选择列、行号、列等

view plaincopy to clipboardprint?
//--------------------------------------------------列选择模式  
    var sm = new Ext.grid.CheckboxSelectionModel({  
    dataIndex:"roleId" 
    });  
    var index= new Ext.grid.RowNumberer();//行号  
    //--------------------------------------------------列头  
     var colModel = new Ext.grid.ColumnModel  
        (  
            [  
                index,  
                sm,  
                {header:"序号",width:100,dataIndex:‘journal_id‘,sortable:true},     
                {header:"期刊名称",width:80,dataIndex:‘journal_name‘,sortable:true},  
                {header:"主办单位",width:110,dataIndex:‘journal_organizer‘,sortable:true},  
                {header:"期刊级别",width:100,dataIndex:‘journal_level‘,sortable:true},  
                {header:"是否核心",width:110,dataIndex:‘is_core‘,sortable:true},  
                
                {header:"操作",width:100,dataIndex:‘journal_id‘,sortable:true,renderer:delfun}  
            ]  
        ); 
//--------------------------------------------------列选择模式
    var sm = new Ext.grid.CheckboxSelectionModel({
 dataIndex:"roleId"
 });
 var index= new Ext.grid.RowNumberer();//行号
 //--------------------------------------------------列头
     var colModel = new Ext.grid.ColumnModel
        (
            [
                index,
             sm,
                {header:"序号",width:100,dataIndex:‘journal_id‘,sortable:true},  
                {header:"期刊名称",width:80,dataIndex:‘journal_name‘,sortable:true},
                {header:"主办单位",width:110,dataIndex:‘journal_organizer‘,sortable:true},
                {header:"期刊级别",width:100,dataIndex:‘journal_level‘,sortable:true},
                {header:"是否核心",width:110,dataIndex:‘is_core‘,sortable:true},
             
                {header:"操作",width:100,dataIndex:‘journal_id‘,sortable:true,renderer:delfun}
            ]
        );

三:定义表格grid

view plaincopy to clipboardprint?
journal_grid = new Ext.grid.GridPanel  
        (  
            {  
                id:‘id_journal_grid‘,                     //grid的id    
                autoHeight:true,  
                autoWidth:true,  
                sm:sm,  
                cm:colModel, //行列  
                loadMask:true,  
                  
                store:journal_store, //数据源  
                  
                trackMouseOver:true, //鼠标特效  
                autoScroll:true,  
                stripeRows:true,  
                viewConfig:{  
                    columnsText:"显示/隐藏列",  
                    sortAscText:"正序排列",  
                    sortDescText:"倒序排列",  
                    forceFit:true 
                }, 
journal_grid = new Ext.grid.GridPanel
        (
            {
                id:‘id_journal_grid‘,                     //grid的id 
                autoHeight:true,
                autoWidth:true,
                sm:sm,
                cm:colModel, //行列
                loadMask:true,
               
                store:journal_store, //数据源
               
                trackMouseOver:true, //鼠标特效
                autoScroll:true,
                stripeRows:true,
                viewConfig:{
           columnsText:"显示/隐藏列",
           sortAscText:"正序排列",
           sortDescText:"倒序排列",
           forceFit:true
          },

四:定义工具栏

view plaincopy to clipboardprint?
tbar:  //工具条  
                [  
                 {                      
                    text: ‘刷新‘,  
                    cls: ‘x-btn-text-icon details‘,  
                   
                    handler: function(btn, pressed)  
                    {//重置查询条件  
                      Ext.getCmp("QueryForm").findById(‘journalName‘).reset();  
                        Ext.getCmp("QueryForm").findById(‘journalOrganizer‘).reset();  
                        Ext.getCmp("QueryForm").findById(‘journalLevel‘).reset();  
                        Ext.getCmp("QueryForm").findById(‘JournalIsCore‘).reset();  
                          journal_store.load({params:{start:0,limit:pageSize}});    
                          //数据源从新加载  
                    }  
                },   
                ‘-‘,   
                {                      
                    text: ‘添加‘,  
                    handler: function(btn, pressed)  
                    {  
                       AddJournalInfo();       //添加新的角色信息  
                         
                    }  
                }, ‘-‘,                 
                {                      
                    text: ‘编辑‘,  
                    handler: function(btn, pressed)  
                    {    
                           var row=Ext.getCmp("id_journal_grid").getSelectionModel().getSelections();//选择行的个数  
                                 if(row.length==0)  
                                {  
                                    Ext.Msg.alert("提示信息","请您至少选择一个!");  
                                }  
                                else if(row.length>1){    
                                    Ext.Msg.alert("提示信息","对不起只能选择一个!");  
                                }else if(row.length==1)  
                                {  
                                   EditJournalInfo(row[0]);//传行一行记录直接加载 编辑角色信息  
                                }                     
                    }  
                }, ‘-‘,                 
                {                      
                    text: ‘删除‘,  
                    handler: function(btn, pressed)  
                    {  
                           var row=Ext.getCmp("id_journal_grid").getSelectionModel().getSelections();    //获取选中的行  
                            if(row.length==0)  
                            {  
                                Ext.Msg.alert("提示信息","请您至少选择一个!");  
                            }  
                            else{    
                                Ext.Msg.confirm("提 示!","您确定要删除吗?",function(btn){   
                                    if(btn=="yes")  
                                    {  
                                                                             
                                       DeleteJournalInfo(row);//删除角色信息  
                                    }  
                                    else 
                                    {  
                                         
                                    }  
                                })  
                            }   
                    }  
                },‘-‘,   
                {                      
                    text: ‘综合查询‘,  
                    handler: function(btn, pressed)  
                    {  
                       
                     Ext.getCmp("QueryForm").toggleCollapse(true);//将formset展开  
                      
                    }  
                }, ‘-‘ 
                ] 
tbar:  //工具条
          [
           {                   
                    text: ‘刷新‘,
                    cls: ‘x-btn-text-icon details‘,
                
                    handler: function(btn, pressed)
                    {//重置查询条件
                      Ext.getCmp("QueryForm").findById(‘journalName‘).reset();
                        Ext.getCmp("QueryForm").findById(‘journalOrganizer‘).reset();
                        Ext.getCmp("QueryForm").findById(‘journalLevel‘).reset();
                        Ext.getCmp("QueryForm").findById(‘JournalIsCore‘).reset();
                          journal_store.load({params:{start:0,limit:pageSize}}); 
                          //数据源从新加载
                    }
                },
                ‘-‘,
                {                   
                    text: ‘添加‘,
                    handler: function(btn, pressed)
                    {
                       AddJournalInfo();       //添加新的角色信息
                      
                    }
                }, ‘-‘,              
                {                   
                    text: ‘编辑‘,
                    handler: function(btn, pressed)
                    { 
                           var row=Ext.getCmp("id_journal_grid").getSelectionModel().getSelections();//选择行的个数
                                 if(row.length==0)
                                {
                                    Ext.Msg.alert("提示信息","请您至少选择一个!");
                                }
                                else if(row.length>1){ 
                                    Ext.Msg.alert("提示信息","对不起只能选择一个!");
                                }else if(row.length==1)
                                {
                                   EditJournalInfo(row[0]);//传行一行记录直接加载 编辑角色信息
                                }                  
                    }
                }, ‘-‘,              
                {                   
                    text: ‘删除‘,
                    handler: function(btn, pressed)
                    {
                           var row=Ext.getCmp("id_journal_grid").getSelectionModel().getSelections();    //获取选中的行
                            if(row.length==0)
                            {
                                Ext.Msg.alert("提示信息","请您至少选择一个!");
                            }
                            else{ 
                                Ext.Msg.confirm("提 示!","您确定要删除吗?",function(btn){
                                    if(btn=="yes")
                                    {
                                                                          
                                       DeleteJournalInfo(row);//删除角色信息
                                    }
                                    else
                                    {
                                      
                                    }
                                })
                            }
                    }
                },‘-‘,
                {                   
                    text: ‘综合查询‘,
                    handler: function(btn, pressed)
                    {
                    
                     Ext.getCmp("QueryForm").toggleCollapse(true);//将formset展开
                   
                    }
                }, ‘-‘
          ]

五:设置分页

view plaincopy to clipboardprint?
//分页  
                bbar:new Ext.PagingToolbar({  
                    store:journal_store,           //数据源  
                    pageSize:pageSize,  
                    //显示右下角信息  
                    displayInfo:true,  
                    displayMsg:‘当前记录 {0} -- {1} 条 共 {2} 条记录‘,  
                    emptyMsg:"No results to display",  
                    prevText:"上一页",  
                    nextText:"下一页",  
                    refreshText:"刷新",  
                    lastText:"最后页",  
                    firstText:"第一页",  
                    beforePageText:"当前页",  
                    afterPageText:"共{0}页" 
                    })  
            }); 
//分页
          bbar:new Ext.PagingToolbar({
           store:journal_store,           //数据源
           pageSize:pageSize,
           //显示右下角信息
           displayInfo:true,
           displayMsg:‘当前记录 {0} -- {1} 条 共 {2} 条记录‘,
              emptyMsg:"No results to display",
              prevText:"上一页",
           nextText:"下一页",
           refreshText:"刷新",
           lastText:"最后页",
           firstText:"第一页",
           beforePageText:"当前页",
           afterPageText:"共{0}页"
                   })
            });

六:设置右键菜单

view plaincopy to clipboardprint?
//为右键菜单添加事件监听器  
      journal_grid.addListener(‘rowcontextmenu‘,rightClickFn);  
       var rightClick = new Ext.menu.Menu  
       (  
           {  
               items:  
               [  
                   {  
                       id: ‘rMenu1‘,  
                       handler:AddJournalInfo,//点击后触发的事件  
                       text: ‘增加角色‘ 
                   },  
                   {  
                       id:‘rMenu2‘,  
                       text:‘编辑角色‘,  
                       handler:function()  
                           {  
                              JournalEdit();  
                           }  
                   },  
                    {  
                       id:‘rMenu3‘,  
                       text:‘删除角色‘,  
                       handler: function()  
                       {  
                          JournalDelete();  
                       }  
                   }  
                     
               ]  
           }  
       );

时间: 2024-10-10 12:47:48

Ext.GridPanel 用法总结(一)—— Grid基本用法的相关文章

extjs grid renderer用法

extjs grid renderer用法 摘自:http://www.cnblogs.com/ljian/archive/2011/10/27/2226959.html var cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer({ header: "", width: 20, align: 'center' }),{ header: '', align: 'center', dataIndex: 'AccountAndRo

ext GridPanel分页

grid.js Ext.onReady(function() { var gridStore = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ url: 'grid.asp' }), reader: new Ext.data.JsonReader({ root: 'data', totalProperty: 'totalCount', idProperty: 'id' },[ {name: 'id',mapping:'id'}, {na

EXT Js 关于动态收缩grid的宽度

Ext js关于动态收缩grid的宽度导致grid不能正常收缩的解决方案: 1.根据"window.document.body.onresize = function ()"事件动态给grid赋值宽度,达到动态收缩的目的,效果比较好,但是会受到浏览器兼容性的限制 2.根据"Ext.EventManager.onWindowResize(function () "这个Ext自带的方法进行处理,默认会有100毫秒的收缩延迟,效果上不太理想:可以参考源码,进行修改去掉延迟

7.1 安装软件包的三种方法7.2 rpm包介绍 7.3 rpm工具用法 7.4 yum工具用法7.5 yum搭建本地仓库

- 7.1 安装软件包的三种方法 - 7.2 rpm包介绍 - 7.3 rpm工具用法 - 7.4 yum工具用法 - 7.5 yum搭建本地仓库 - 扩展 1. yum保留已经安装过的包 http://www.360doc.com/content/11/0218/15/4171006_94080041.shtml 2. 搭建局域网yum源 http://ask.apelearn.com/question/7627 # 7.1 安装软件包的三种方法 - windows的.exe文件实际上是一种二

ext.net 2.5 导出excel的用法

前台页面的导入,导出 <ext:FileUploadField ID="FileUploadField_Import" runat="server" ButtonOnly="true" ButtonText="导入" Icon="PackageIn"> <DirectEvents> <Change OnEvent="ImportExcelClick">

【Ext.Net学习笔记】03:Ext.Net DirectEvents用法详解、DirectMethods用法详解

position:static(静态定位) 当position属性定义为static时,可以将元素定义为静态位置,所谓静态位置就是各个元素在HTML文档流中应有的位置 podisition定位问题.所以当没有定义position属性时,并不说明该元素没有自己的位置,它会遵循默认显示为静态位置,在静态定位状态下无法通过坐标值(top,left,right,bottom)来改变它的位置. position:absolute(绝对定位) 当position属性定义为absolute时,元素会脱离文档流

Ext GridPanel

Extjs GridPanel用法详解 创建GridPanel 要使用GridPanel,首先要定义Store,而在创建Store的时候必须要有Model,因此我们首先来定义Model: //1.定义Model Ext.define("MyApp.model.User", { extend: "Ext.data.Model", fields: [ { name: 'name', type: 'string' }, { name: 'age', type: 'int'

关于EXT gridPanel进行高级查询时load提交后台乱码以及其他方式更新store的方法及遇到的问题

Ext.data.Store  加载数据的几个方法及注意的事项 下面为定义的Store var ds_edisCommonUser = new Ext.data.uStore({ storeId:'edisCommonUser', model:'Edis_CommonUser', pageSize:itemPerPage, autoLoad:false, proxy:{ type:'ajax', method:'POST', url:'EdisCommonUser/getUsers.action

逻辑表达式的用法 与或非的用法

先说逻辑与(&&),它可以从三个层次进行理解 第一个层次最简单,就是简单的布尔值之间的逻辑与,就是左值和右值都是true时,返回true,两边都是false或者两边的值其中一边是fasle,就返回false:(AND操作): 第二个层次,(false,null,indefined,0,-0,NaN和""这些都是假值,其他所有的值包括对象都是真值),对这些"真值"和"假值"进行AND操作,返回一个"真值"或者&q