`
kidiaoer
  • 浏览: 822190 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

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

阅读更多
Ext.GridPanel 用法总结(一)—— Grid基本用法

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();  
                       }  
                   }  
                     
               ]  
           }  
       );
分享到:
评论

相关推荐

    Ext+JS高级程序设计.rar

    目录 前 言 第一部分 Ext Core 第1章 Ext Core重要概念 2 1.1 Ext.Element 2 1.1.1 获取HTMLElement节点的Ext.Element实例 2 1.1.2 CSS样式操作 3 1.1.3 DOM查询与遍历 4 1.1.4 DOM操作 6 ...14.14 本章小结 483

    Ext中文文档

    - **资源与小结**:列出了一系列辅助学习的资源,并对准备阶段进行了总结,强调了资源的重要性。 #### 第三章:ExtOOP基础 - **javascript类的定义与Extjs命名空间**:深入探讨了在ExtJS中如何定义类和命名空间,...

    ExtJs中文教程

    - 结合实际案例介绍XTemplate的使用方法。 #### 八、Extjs组件结构 1. **组件结构解析** - 解释ExtJs组件体系结构的复杂性。 2. **组件分类** - 分类介绍不同类型的组件及其用途。 3. **组件生命周期** - 描述...

    extjs中文教程

    ### 第十六部分:表格组件——GridPanel GridPanel是ExtJS中处理表格数据的高级组件。本部分详细介绍了GridPanel的使用,包括列模型、数据管理,以及如何实现分页和扩展GridPanel。 ### 第十七部分:行模型与Grid...

    Extjs中文教程

    - 可以帮助用户更好地理解控件的作用和使用方法。 - **悬停提示的用法** - 通常使用`qtip`属性来设置提示文本。 - 也可以通过JavaScript动态设置提示内容。 - **表单组件验证** - 表单验证是确保用户输入数据...

    轻松搞定Extjs

    - **Ext.Panel类**: 详细介绍了一种常用的面板类型——`Panel`,以及其配置选项和使用方法。 #### Panel的子类——Window窗口 窗口是面板的一种特殊形式,可以独立弹出显示。 - **概述**: 简要介绍了窗口的基本...

    Ext JS in Action (Final Edition).pdf

    - **第8章:Editor Grid Panel**(The Editor Grid Panel):介绍了编辑功能更加强大的GridPanel变体——Editor Grid Panel。 - **第9章:DataView与ListView**(DataView and ListView):解释了DataView和...

Global site tag (gtag.js) - Google Analytics