Ext之grid右键菜单

  1. Ext.ns('Ext.ux.grid');  
  2. Ext.ux.grid.RightMenu = function(options) {  
  3.     var currRecord = false;  
  4.     var currRowIndex = false;  
  5.     var currGrid = false;  
  6.     var menuItems = Ext.each(options.items, function() {  
  7.                 var item = this;  
  8.                 this.handler = function() {  
  9.                     item.recHandler  
  10.                             && item.recHandler(currRecord, currRowIndex,  
  11.                                     currGrid);  
  12.                 };  
  13.             });  
  14.     var menu = new Ext.menu.Menu({  
  15.                 items : options.items  
  16.             });  
  17.     this.init = function(grid) {  
  18.         grid.addListener('rowcontextmenu'function(client, rowIndex, e) {  
  19.                     e.preventDefault();  
  20.                     if (rowIndex < 0) {  
  21.                         return;  
  22.                     }  
  23.                     client.getSelectionModel().selectRow(rowIndex);  
  24.                     currRowIndex = rowIndex;  
  25.                     currRecord = grid.getStore().getAt(rowIndex);  
  26.                     currGrid = grid;  
  27.                     menu.showAt(e.getXY());  
  28.                 });  
  29.     };  
  30. };  

[javascript]  view plain copy
  1. var rightMenu = new Ext.ux.grid.RightMenu({  
  2.             items : [{  
  3.                         text : '增加',  
  4.                         recHandler : onAdd  
  5.                     }, {  
  6.                         text : '删除',  
  7.                         recHandler : function(record, rowIndex, grid) {  
  8.                             alert(1);  
  9.                         }  
  10.                     }]  
  11.         });  

只需要将上面代码作为插件使用就OK了

[javascript]  view plain copy
  1. selModel : new Ext.grid.RowSelectionModel({  
  2.             singleSelect : true  
  3.         }),  
  4. plugins : [rightMenu],  

你可能感兴趣的:(JavaScript,function,ext,plugins)