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'));
}
}]
}
]
});
});
5
A
回答
11
grid.getStore().remove(rec); //or rec.destroy() if the url specified in model
9
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);
}
}]
}
]
});
});
相關問題
- 1. 如何添加編輯,如下刪除了JQ網格按鈕的每一行
- 2. 如何在編輯數據網格中的行時禁用刪除按鈕
- 3. 如何使用網格外的刪除按鈕在gridview中刪除一行?
- 4. 爲數據網格中的每一行添加刪除按鈕
- 5. 編輯和刪除表格數據的每一行按鈕?
- 6. 如何在KendoUI的網格模板中製作編輯按鈕?
- 7. 編輯ExtJs網格中的一行
- 8. 刪除網格行
- 9. 如何使用WPF刪除網格中的最後一行?
- 10. 劍道MVC:添加編輯,刪除按鈕網格
- 11. 從網格中刪除行取決於按鈕的值
- 12. 如何使用JqGrid子網格進行內聯編輯?
- 13. 編輯數據網格行
- 14. GXT 2.2.4網格行編輯
- 15. 如何在uigrid中刪除一行,如果按鈕位於網格之外
- 16. 如何在GXT3網格中添加(添加,編輯,刪除)按鈕
- 17. 如何在網格視圖中添加刪除,更新或編輯按鈕?
- 18. 如何使用刪除按鈕刪除表格行
- 19. 如何禁止用戶刪除數據網格中的一行?
- 20. 在Silverlight數據網格中編輯,添加和刪除行?
- 21. 從網格視圖編程刪除行
- 22. 網格使用JavaScript進行內聯編輯,怪異行爲
- 23. 刪除表格行中的按鈕
- 24. 使用按鈕編輯WPF數據網格單元格
- 25. 從網格刪除空行
- 26. Kendo - 網格 - 刪除多行
- 27. LibGDX從模板編輯模型網格
- 28. 如何觸發按鈕單擊事件編輯Telerik網格中的行
- 29. 網格內的DOJO按鈕
- 30. 如何編輯網格行以刪除下劃線中的下劃線
編輯第一和actioncolumn點擊第二列有什麼建議? – FlashyFuddyFuddy
@FlashyFuddyFuddy查看github上的活動示例:http://htmlpreview.github.com/?https://github.com/werdender/ext4examples/blob/master/actioncolumns-edit.html – Vlad
謝謝弗拉德! :)這真的幫了很多! – FlashyFuddyFuddy