Delete / Modify database records from EditorGrid panel
I am using ExtJs with Rails 3.x . How to delete/modify records from EditorGrid using Ext.Ajax.request method?
I tried using store.remove()
and similar other methods but it doesn't remove record from database.
Thanks in advance !!
Code :
//** Destroy method **//
def destroy
puts 'destroy'
@unit = Unit.find(params[:id])
puts 'will destroy'
@unit.destroy
puts 'destroyed'
end
//** units.js **//
var delbtn = Ext.getCmp('btnDelete');
delbtn.on('click',function(){
var grid = Ext.getCmp('maingrid');
var selection = grid.getSelectionModel().getSelected();
Ext.Ajax.request({
url: '/units/destroy',
method: 'POST',
params: {
'id' : selection.data.id }
});
});//end del function
//** Store.js **//
Ext.data.Api.restActions = {
create : 'POST',
read : 'GET',
update : 'PUT',
destroy : 'DELETE' };
storeId: 'MyUnitStore',
root: 'data',
autoLoad: true,
autoSave: false,
//batch: true,
restful:true,
writer: new Ext.data.JsonWriter({
encode : false,
listful:开发者_JS百科false,
destroy: '/units/destroy',
update : '/edit'
}),
url: '/units.json',
fields: [
{
name: 'unitname'
},
{
name: 'description'
}
]
//** Edit Button **//
var store = Ext.getCmp('maingrid').getStore();
store.update();
store.remove()
removes the data (record) from your grid's associated store only. It does not communicate with server side by itself. You need to use the Ajax request and communicate with Rails 3.x to get the appropriate record deleted.
var selection = grid.getSelectionModel().getSelected();
Ext.Ajax.request({
url: '/ExampleController/Delete',
method: 'POST',
params: {
'id': selection.data.id
},
success: function(result, request){
// Refresh the grid store and display
},
failure: function(result, request){
// Display delete error message
}
}
精彩评论