1

我是 Ext JS 的新手,我需要更新一个旧应用程序。EditorGridPanel 有一个“添加”按钮,它工作正常。但是,我需要添加一个“删除”按钮,从网格中删除该行。这是网格的代码。谢谢你的帮助。

 /*==== INVOICE DATA START =======================================================*/
    var iLineItemCM = new Ext.grid.ColumnModel([
         {id:'i_line_item_name', header: "Line Item Name", dataIndex:     'i_line_item_name', width: 280,
           editor: new Ext.form.TextField({allowBlank: false})}
        ,{header: "Amount", dataIndex: 'i_line_item_amt', width: 80, align: 'right', renderer: 'usMoney',
         editor: new Ext.form.NumberField({
               allowBlank: false,
               allowNegative: false,
               maxValue: 100000
           })}
        ]);

    var iLineItemRec =
        new Ext.data.Record.create([
            {name: 'i_line_item_name'    ,mapping: 'i_line_item_name'  ,type: 'string'}
           ,{name: 'i_line_item_amt'     ,mapping: 'i_line_item_amt'   ,type: 'string'}
         ]);

    var iLineItemStore = new Ext.data.Store({
        url: '',
        reader: new Ext.data.JsonReader({
               root: 'rows'
         },
           iLineItemRec
        )
    });

    var iLineItemGrid = new Ext.grid.EditorGridPanel({
        store: iLineItemStore,
        cm: iLineItemCM,
        width: 'auto',
        height: 'auto',
        //title:'Edit Plants?',
        frame:false,
        //plugins:checkColumn,
        clicksToEdit:1,
        viewConfig: {
            //forceFit: true,
            autoFit:true
      },
      id: 'iLineItemStore',
        tbar: [{
            text: 'Add Line Item',
            handler : function(){
               var r = new iLineItemRec({
                   i_line_item_name: '',
                    i_line_item_amt: ''
               });
                iLineItemGrid.stopEditing();
               iLineItemStore.insert(0, r);
               iLineItemGrid.startEditing(0, 0);
          }
      }]
    });

 ///////////////////
4

1 回答 1

1

来自单元选择模型的文档:http ://docs.sencha.com/ext-js/2-3/#!/api/Ext.grid.CellSelectionModel

单元模型被指定为默认值。

getSelectedCell( ) : Array
Returns the currently selected cell's row and column indexes as an array (e.g., [0, 0]).

所以......像

 { text: 'Remove', 
  tooltip:'Remove the selected item',
  handler: function(){ 
  iLineItemGrid.stopEditing();
  var r = iLineItemGrid.getSelectionModel().getSelectedCell();
  iLineItemStore.removeAt(r[1]); } }
于 2012-05-18T13:04:24.113 回答