PDA

View Full Version : Grid row deletion



mfeldheim
1 Feb 2011, 3:14 AM
I have a grid populated with data from a Jsonstore with ajax api backend.
When deleting a record from the datastore the grid row disappears properly, the ajax request is executed but then for some strange reason the grid row reappears again.

The Json store has the data removed properly at this point.
When I suspend store events ( store.suspendEvents ) just before I call store.save() the grid row disappears and stays away.

Any idea what event could cause the grid to bring the deleted row back?



var proxy = new Ext.data.HttpProxy({
api: {
read: '/ajax/search/',
destroy: '/ajax/delete/'
}
});

var writer = new Ext.data.JsonWriter({
encode: true,
writeAllFields: false
});

var store = new Ext.data.JsonStore({
proxy: proxy,
writer: writer,
autoLoad: true,
autoSave: false
});

var grid = new Ext.grid.GridPanel({
colums: [...],
stateful: true,
stateId: 'grid',
listeners: {
rowcontextmenu: function( grid, rowIndex, event ){
// context menu here which offers the delete and calls the delete function below
}
}

});

function delete()
{
var store = grid.getStore();
var records = grid.getSelectionModel().getSelections();

store.remove( records ); // grid row disappears properly
store.save(); // ajax request is fired, grid row reappears again
}

Barzoy
1 Feb 2011, 3:51 AM
Please post some data which server returns in response of record deletion query. Probably, your data reader just cant read that response properly to concider it successful. So, it rollbacks all changes you made to data store.

mfeldheim
2 Feb 2011, 5:19 AM
That might be the reason since my server response contains only human readable debug messages ( and HTTP 200 ).
Do you have any tip where I can find examples how a response could look like / how to evaluate the response in js correctly?

mfeldheim
2 Feb 2011, 7:06 AM
Didnt realize that I actually configured the store api with serverside metadata and that this applies not only for reads but also for all other store api requests



{
"metaData":{
"idProperty":"id",
"totalProperty":"results",
"root":"rows",
"successProperty":"success",
"fields":[
{"name":"id"},
{"name":"type"},
{..}
]
}
}



{"success":"true","message":"Entry deleted successfully"}
In the deletion response solved the "problem"

More here:
http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.JsonReader