2012-05-17 2 views
1

Я новичок в Ext JS, и мне нужно обновить старое приложение. В редактореGridPanel есть кнопка «ADD», и она отлично работает. Однако мне нужно добавить кнопку «DELETE», которая удаляет строку из сетки. Вот код в сетке. Спасибо за вашу помощь.Удалить строку из EditorGridPanel в Ext JS 2.0.2

/*==== 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); 
      } 
     }] 
    }); 

/////////////////// 
+0

Здравствуйте, я попробовал этот код и он не работает. { текст: 'Удалить', всплывающая подсказка: 'Удалить выбранный элемент', обработчик: function() { iLineItemGrid.stopEditing(); var r = iLineItemGrid.getSelectionModel(). GetSelected(); iLineItemStore.removeAt (r [0]); } } – michael

ответ

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]); } } 
+0

Спасибо, что сработало просто отлично. – michael

Смежные вопросы