grid里面添加右键菜单代码!

来源:互联网 发布:openresty 部署 php 编辑:程序博客网 时间:2024/05/17 22:28

     grid.on("rowcontextmenu",function(grid,rowIndex,e)
        {
            e.preventDefault();if(rowIndex<0){return;}
            var treeMenu = new Ext.menu.Menu
            ([
                {xtype:"button",text:"添加",icon:"Images/Icons/button/add.gif",pressed:true,handler:function(){}},
                {xtype:"button",text:"编辑",icon:"Images/Icons/button/delete.gif",pressed:true,handler:function(){}},
                {xtype:"button",text:"隐藏",icon:"Images/Icons/arrow-down.gif",pressed:true,handler:function(){}},
                {xtype:"button",text:"显示",icon:"Images/Icons/arrow-up.gif",pressed:true,handler:function(){}},
                {xtype:"button",text:"删除",icon:"Images/Icons/button/cross.gif",pressed:true, handler:function(){}},               
                {xtype:"button",text:"上传图片",icon:"Images/Icons/plugin_add.gif",pressed:true,handler:function(){}}
            ]);
            treeMenu.showAt(e.getPoint());
        }); 

 

=============================================================================================

grid.on("rowcontextmenu",function(grid,rowIndex,e)  //以下是关键代码
        {
           
//grid 可以是任何参数名称,意思指的就是表示当前的grid 
           
//rowIndex 表示当前行的索引 第一行是0 依此类推
            e.preventDefault();//覆盖默认右键
            if(rowIndex<0){return;}//如果没有数据就返回
           
 //grid.getStore() 指的是获取当前的存储在客户端的数据集合
            //grid.getStore().getAt(rowIndex) 根据当前行的索引获取当前行的数据
            var record = grid.getStore().getAt(rowIndex);
           
//下面具体获取某个属性的值
            var number = record.json.Row;//编号
            var id = record.data.ID;
            var typeCName = record.data.TypeCName;
            var delFlag = record.data.DelFlag; 
            var addDate = record.data.AddDate.format("Y年m月日");
           
//下面将获取的信息
            var treeMenu = new Ext.menu.Menu
            ([
                {
                    xtype:"button",
                    text:"显示详细信息",
                    icon:"../images/add.gif",
                    pressed:true,
                    handler:function()
                    {
                       
//处理在某行上右键时 显示该行的详细信息
                        var win = new Ext.Window
                        ({
                             title:"显示在某行右键的详细信息",width:337,height:220,layout:'form',modal:false,resizable:false,
                             items:
                             [
                                 {
                                    xtype:"form",
                                    height:200,
                                    labelPad : 0, 
 // 标签与字段录入框之间的空白
                                    bodyStyle : 'padding-top:3px',
                                    frame : true,
                                    defaultType : 'textfield',
                                    labelAlign : 'right',
                                    labelWidth : 81,
                                    defaults :
// 容器中组件默认统一配置选项 
                                    {
                                        allowBlank : true,width : 200  // 字段宽度                            
                                    },
                                    items :
                                    [
                                         {fieldLabel:"编号",id:"RowNumber",value:number},
                                         {fieldLabel:"ID",id:"ID",value:id},
                                         {fieldLabel:"中文名称",id:"TypeCName",value:typeCName},                                                                             
                                         {fieldLabel:"当前状态",id:"DelFlag",value:delFlag},
                                         {fieldLabel:"添加日期",id:"AddDate",value:addDate}
                                    ]
                                }
                             ],
                             buttons:
                             [
                                {xtype:"button",text:"关闭",cls:"x-btn-text-icon",icon:"../images/plugin_add.gif",id:"btnClose",handler:function(){win.destroy();}}
                             ],
                             buttonAlign:"center"
                         });
                         win.show();                       
                    }
                }
            ]);
            treeMenu.showAt(e.getPoint());
        });

==========================================================================

  1. groupGrid.on("rowcontextmenu"function (grid, rowIndex, e) {    
  2.     e.preventDefault();    
  3.     if (rowIndex < 0) {    
  4.         return;    
  5.     }    
  6.     var treeMenu = new Ext.menu.Menu ([    
  7.         {    
  8.             xtype: "",    
  9.             text: "详细",    
  10.             iconCls: 'context-dog',    
  11.             pressed: false,    
  12.             handler: function () {    
  13.                 //获得行数据    
  14.                 var record = grid.getStore().getAt(rowIndex);    
  15.                 //open_receive_detailWindow(record.data.smsIndex);   
  16.                 alert(record.data.company);  //company为自定义的字段名称  
  17.                 //record.data.taskId    
  18.             }    
  19.         }, {    
  20.             xtype: "",    
  21.             text: "删除",    
  22.             iconCls: 'context-cat',    
  23.             pressed: false,    
  24.             handler: function () {    
  25.                 //获得行数据    
  26.                 var record = grid.getStore().getAt(rowIndex);    
  27.                 alert(record.data.company);    
  28.             }    
  29.         }    
  30.     ]);    
  31.     treeMenu.showAt(e.getXY());     
  32. });