2013-02-02 52 views
5
Ext.onReady(function() { 
Ext.define('User', { 
    extend: 'Ext.data.Model', 
    fields: [ 'name', 'class', 'view', 'edit', 'delete'] 
}); 
var userStore = Ext.create('Ext.data.Store', { 
    model: 'User', 
    data: [ 
     { name: 'Sri Vidhya', class: '6 A'}, 
     { name: 'Rafla', class: '9 C'}, 
     { name: 'Fabin', class: '10 B'}, 
     { name: 'Jayanthi', class: '8 C'}, 
     { name: 'Sri Vidhya', class: '6 A'}, 
     { name: 'Rafla', class: '9 C'}, 
     { name: 'Fabin', class: '10 B'}, 
     { name: 'Jayanthi', class: '8 C'}, 
     { name: 'Sri Vidhya', class: '6 A'}, 
     { name: 'Rafla', class: '9 C'}, 
     { name: 'Fabin', class: '10 B'}, 
     { name: 'Jayanthi', class: '8 C'} 
    ] 
}); 
Ext.create('Ext.grid.Panel', { 
    cls: 'custom-grid', 
    renderTo: Ext.getBody(), 
    store: userStore, 
    width: 389, 
    height: 200, 
    title: 'Student Details', 
    columns: [ 
     { 
      text: 'Student Name', 
      cls: 'studentName', 
      width: 100, 
      sortable: true, 
      hideable: false, 
      dataIndex: 'name' 
     }, 
     { 
      text: 'Student Class', 
      cls: 'studentClass', 
      width: 150, 
      sortable : true, 
      dataIndex: 'class' 
     }, 
     { 
      xtype:'actioncolumn', 
      width:40, 
      tdCls:'delete', 
      items: [{ 
       icon: 'Delete-icon.png', // Use a URL in the icon config 
       tooltip: 'Delete', 
       handler: function(grid, rowIndex, colIndex) { 
        var rec = grid.getStore().getAt(rowIndex); 
        //**rec.store.remove();** 
        //rec.store.remove()` is not working. 

        Suggest me the code that will work here to remove the //entire row? 
        alert("Delete " + rec.get('name')); 
       } 
      }] 
     }, 
     { 
      xtype:'actioncolumn', 
      tdCls:'edit', 
      width:40, 
      items: [{ 
       icon: 'edit-icon.png', // Use a URL in the icon config    
       tooltip: 'Edit', 
       handler: function(grid, rowIndex, colIndex) { 
        var rec = grid.getStore().getAt(rowIndex); 
        alert("Edit " + rec.get('name')); 
       } 
      }] 
     }, 
     { 
      xtype:'actioncolumn', 
      tdCls:'view', 
      width:40, 
      items: [{ 
       icon: 'view-icon.png', // Use a URL in the icon config   
       tooltip: 'View', 
       handler: function(grid, rowIndex, colIndex) { 
        var rec = grid.getStore().getAt(rowIndex); 
        alert("View " + rec.get('name')); 
       } 
      }] 
     } 
    ] 
}); 
}); 

उत्तर

11
grid.getStore().remove(rec); //or rec.destroy() if the url specified in model 
+0

संपादन पहली और actioncolumn क्लिक पर दूसरे स्तंभ के लिए कोई सुझाव? – FlashyFuddyFuddy

+0

@ फ्लैशीफड्डीफड्डी जीथ्यूब पर लाइव उदाहरण देखें: http://htmlpreview.github.com/?https://github.com/werdender/ext4examples/blob/master/actioncolumns-edit.html – Vlad

+0

धन्यवाद व्लाद! :) कि वास्तव में बहुत मदद की! – FlashyFuddyFuddy

9
grid.getStore().removeAt(rowIndex) 
+1

धन्यवाद ... यह भी काम करता है :) – FlashyFuddyFuddy

1
//My Code Updated with delete options 




Ext.onReady(function() { 
Ext.define('User', { 
    extend: 'Ext.data.Model', 
    fields: [ 'name', 'class', 'view', 'edit', 'delete'] 
}); 
var userStore = Ext.create('Ext.data.Store', { 
    model: 'User', 
    data: [ 
     { name: 'Sri Vidhya', class: '6 A'}, 
     { name: 'Rafla', class: '9 C'}, 
     { name: 'Fabin', class: '10 B'}, 
     { name: 'Jayanthi', class: '8 C'}, 
     { name: 'Sri Vidhya', class: '6 A'}, 
     { name: 'Rafla', class: '9 C'}, 
     { name: 'Fabin', class: '10 B'}, 
     { name: 'Jayanthi', class: '8 C'}, 
     { name: 'Sri Vidhya', class: '6 A'}, 
     { name: 'Rafla', class: '9 C'}, 
     { name: 'Fabin', class: '10 B'}, 
     { name: 'Jayanthi', class: '8 C'} 
    ] 
}); 
Ext.create('Ext.grid.Panel', { 
    cls: 'custom-grid', 
    renderTo: Ext.getBody(), 
    store: userStore, 
    width: 389, 
    height: 200, 
    title: 'Student Details', 
    /*selType: 'User', 
    plugins: [ 
     Ext.create('Ext.grid.plugin.CellEditing', { 
      clicksToEdit: 1 
     }) 
    ],*/ 
    columns: [ 
     { 
      text: 'Student Name', 
      cls: 'studentName', 
      width: 100, 
      sortable: true, 
      hideable: false, 
      dataIndex: 'name' 
      /*editor: 'textfield'*/ 
     }, 
     { 
      text: 'Student Class', 
      cls: 'studentClass', 
      width: 150, 
      sortable : true, 
      dataIndex: 'class' 
      /*editor: 'textfield'*/   
     }, 
     { 
      xtype:'actioncolumn', 
      tdCls:'view', 
      width:40, 
      items: [{ 
       icon: 'view-icon.png', // Use a URL in the icon config   
       tooltip: 'View', 
       handler: function(grid, rowIndex, colIndex) { 
        var rec = grid.getStore().getAt(rowIndex); 
        alert("View " + rec.get('name')); 
       } 
      }] 
     }, 
     { 
      xtype:'actioncolumn', 
      tdCls:'edit', 
      width:40, 
      items: [{ 
       icon: 'edit-icon.png', // Use a URL in the icon config    
       tooltip: 'Edit', 
       handler: function(grid, rowIndex, colIndex) { 
        var rec = grid.getStore().getAt(rowIndex); 
        alert("Edit " + rec.get('name')); 
       } 
      }] 
     }, 
     { 
      xtype:'actioncolumn', 
      width:40, 
      tdCls:'delete', 
      items: [{ 
       icon: 'Delete-icon.png', // Use a URL in the icon config 
       tooltip: 'Delete', 
       handler: function(grid, rowIndex, colIndex) { 
        var rec = grid.getStore().getAt(rowIndex); 
        //rec.store.remove(); 
        alert("Delete " + rec.get('name')); 
        grid.getStore().remove(rec); 
        //grid.getStore().removeAt(rowIndex); 
       } 
      }] 
     } 
    ] 
}); 
});