PDA

View Full Version : Problem loading the grid store



Guboed
16 Mar 2011, 2:14 AM
Hello all

I have a problem reloading the store after deleting a record in the grid.
After deleting the record, the grid loads for a few seconds and the record is getting deleted at the back end.
But ExtJs was still trying to fetch the deleted records from the source, which is generating an exception in the java code. I am using a pagination grid which displays 10 records on every page.Whenever i delete a record, the page is unable to fill the void left by the deleted records. But when i click on the refresh icon on the pagination bar, it is fetching the records in place of the deleted records. Please share your thoughts on this issue.

Thanks in advance.

This is the function i call every time i delete a record..



function Delete(isLocked, documentId)
{
if (isLocked == "false") {
var panelContent;
var win;
var button = Ext.get('Delete');
win = new Ext.Window({
// applyTo:'help-win',
title : 'Delete details',
id : 'deletewin',
closable : false,
closeAction : 'hide',
width : 200,
height : 120,
border : false,
plain : true,
autoLoad : {
url : 'deleteRevision.jsp',
params : {
'documentId' : documentId
},
scripts : true,
nocache : true
},

buttons : [{
text : 'OK',
id : 'message_box',
cls : 'x-icon-btn',
iconCls : 'x-icon-btn-ok',
handler : function() {
var record = grid.getSelectionModel().getSelected();
if(record != undefined)
grid.store.remove(record);
Ext.getCmp("deletewin").close();
grid.getStore().reload();


}
}]
});
win.show();
}
}
This is my store definition



dataStore = new Ext.data.Store({
// load using script tags for cross domain
proxy : new Ext.data.HttpProxy({
url : 'assets.jsp',
method : 'GET'
}),
// let it know about the reader
reader : reader,
autoLoad : {
params : {
start : 0,
limit : 10
}
}
});

Grolubao
16 Mar 2011, 2:46 AM
You're doing it in a wrong way. When you click save you have two options: Or you use Ext.Direct and then just use store.save(); and that's it, or you use a normal Ajax.request and on the callback you load the store again.

Don't use defer!! Somebody would kill you for that :P

Guboed
16 Mar 2011, 3:18 AM
Thanks for the prompt reply.

I wasn't saving anything in the grid. I just wanted to reload the grid with all the new records replacing the deleted ones. I am a beginner in ExtJs, so if you don't mind, please care to explain in detail.

steffenk
16 Mar 2011, 3:47 AM
grid.store.remove(record);
Ext.getCmp("deletewin").close();
grid.getStore().reload();

this is your problem.
1) you close the window before doing something else
2) you don't need to reload when removing a record

try this way:

var gridstore = grid.store;
gridstore.remove(record);
gridstore.commit(); // this should fire a request to delete the record in your BE
win.close(); //you already have a reference to your window

grid.getStore().reload();

Guboed
16 Mar 2011, 4:37 AM
Steffenk, Thanks for the reply.

Please see the attachment.

I did as you told, but the problem still persists.
If i remove the line grid.getStore().reload(), then it doesnt generate any exception,
but it also doesnt fetch the new records into the page. So i have to reload the grid after deleting any record. How can we fetch the new records into the current page without a reload.(Even reload isnt fetching the records). We are supposed to have ten records on every page, then if we delete any of these records, it should reload and readjust the page with 10 records by fetching new records in place of the deleted ones.

steffenk
16 Mar 2011, 4:59 AM
Then something else is wrong. The grid displays the records from store. If you remove a record, it is removed from grid too.
Are you sure you have correct id's for the records? Are you sure you fetched correct record?

Try with console first:

datastore.remove(datastore.getAt(0));
The grid should be updated as well.

Guboed
16 Mar 2011, 5:19 AM
Yes , all the records with the correct ID's were getting deleted.
If you see the attachment, after deleting every record that alert box is displayed.
If i immediately click OK on the alert box, then this problem is happening.
If i leave the alert box without clicking the OK button, say for 5 seconds it is then reloading the grid fetching 10 records on the page which is the desired output.