2009-09-29 79 views
11

我对Extjs很新。 是否有人知道如何将按钮添加到Extjs中的每一行网格? 请给我一些例子。在ExtJs中添加按钮到网格

感谢

+2

接受一个答案。 – 2012-12-27 09:50:42

回答

4

你应该使用一个自定义渲染,但我建议你使用一个工具栏按钮,而不是更干净。

如果您想要更多参考,请参阅ColumnModel类的documentation

无论如何,它会给类似的东西

var grid = new Ext.grid.GridPanel({ 
     store: store, 
     columns: [ 
      {id:'company',header: 'Company', width: 160, sortable: true, dataIndex: 'company'}, 
      {header: 'Price', width: 75, sortable: true, renderer: 'usMoney', dataIndex: 'price'}, 
      {header: 'Change', width: 75, sortable: true, renderer: change, dataIndex: 'change'}, 
      {header: '% Change', width: 75, sortable: true, renderer: pctChange, dataIndex: 'pctChange'}, 
      {header: 'Last Updated', width: 85, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}, 
      {header: 'action', width: 85, sortable: false, renderer: function(val){ return '<input type="button" value="toto" id="'+val+'"/>'; }, dataIndex: 'somefieldofyourstore'} 


     ], 
     stripeRows: true, 
     autoExpandColumn: 'company', 
     height: 350, 
     width: 600, 
     title: 'Array Grid', 
     // config options for stateful behavior 
     stateful: true, 
     stateId: 'grid'   
    }); 

这个片段是this sample的提取物。

对于工具栏方式,我建议你,只需在GridPanel的工具栏中添加一个按钮,然后钩住SelectionModel,以便在用户不选择任何行时禁用这些按钮。

+0

伙计们:任何想法如何可以在ListView中完成也?????? – bensiu 2011-01-18 04:57:33

+0

@bensui:我认为在列表中您必须提供模板来创建标记,所以是的... – RageZ 2011-01-18 08:20:54

6

Actualy Ext.Buttons in a row cell is as as i can tell tell impossible with the current setup of Ext。当然,实际上可以在单元格的div中呈现按钮的HTML,但我实际上认为这是一个坏主意。

更好的方法是实现Saki的rowactions插件,这使得向每行添加按钮/操作变得非常简单。

http://rowactions.extjs.eu/

0

我要一个额外的答案添加到这个问题,因为,因为这问题已发布我已经创造了ExtJS的网格组件,它允许按钮被添加到网格列的延伸。

https://github.com/Inventis/Ext.ux.grid.ButtonColumn

要知道,呈现大量行的时候它可能会影响到对旧/较慢的系统性能。

2

ü也可以尝试在网格这里添加按钮图像此代码代码:

 new Ext.grid.ColumnModel([ { 
        xtype : 'actioncolumn', 
        header : "Action", 
        items : [ { 
         icon : '../images/enable.png', 
         tooltip : 'Enable App', 
         width : 50, 
         id:'enableAppId', 
         handler : function(grid, rowIndex) { 
          //add code for button click 
         } 
        }] 
        } ] 

) 

我也用这个使该行数据