PDA

View Full Version : Store and grid "refresh" after row edit



cripkd
12 Aug 2009, 11:04 PM
Hi.
I have a grid setup with row editing.
I have this store:


var store = new Ext.data.GroupingStore({
reader: new Ext.data.JsonReader({fields: Category}),
//data: sdata,
sortInfo: {field: 'category_name', direction: 'ASC'},
listeners:{
'load':function(){
grid.getSelectionModel().selectRow(0);
},
'update':function(a,b,c){
if(!justAdded){
editCategory(conn, b.data);
}else {
newCatId = addCategory(conn, b.data, grid, this);

//grid.getStore().reload();

//grid.refresh();
}

},
'add':function(){
justAdded = 1;
}
}
});


Editing works, but adding new rows is tricky.
I managed to cover that, sending the new data to the server and saving it, ok (although maybe it can be done in a nicer way? Now i set a flag on the add event, so that I can differenciate between edits and new items inside the "update" event, don;t know how to handle it otherwise), but I don't know how to make the frid reflect the changes.

I mean the new item DOES show in the grid, of course, but its underlying data is not, clicking the new row throws up errors because there is no json for that row.
So i tried store.reload(), but doesn't work, forum and docs say you need reload or load for external data, but errors say i don't have a proxy. What does that mean, i never used on in the first place, when i first load the grid, and it works. If there is some underlying implicit proxy somewhere, why doesn't it exist on reload?

If i manage to get the store reloaded (cos i need the id of the new item beeing inserted in the database), do I also need a grid.refresh()? Will that work?
Thanks.

tubamanu
13 Aug 2009, 1:46 AM
hi,

actually i didnt use editing grid combined with an grid to add new records. last time i used edit grid and a button in toolbar for new entries, but i insert them using a ext window component....but i'm sure theres a way to handle update and save action in a grid. maybe someone knows more.....

for your store, u need to add some kind of url, from where u get your data or where u want to get your data after refresh.



this.theGridStore = new Ext.data.JsonStore({
totalProperty: 'total',
root: 'result',
url: 'load.php',
autoload: true,
fields: [
{name: '#'},
{name: 'vorname'},
{name: 'nachname'}
]
});


if u want to refresh your grid, u only need to call yourStore.refresh();
if your store is binded to grid, it refreshes automatic.

if u want to refresh your grid after adding new entry to database, u can use extjs ajaxfunctionality and add the record on serverside to database, and after success refresh the grid on client side....

cripkd
13 Aug 2009, 3:03 AM
What exactly do you call binding a store? Just having a store config option when i define the frid? I already do. Otherwise, i can find no bindStore method, like a ViewData's.

I didn't use an url option for my store, I just do an ajax call on the beforerender event on my viewport (to which the grid is stuck, as an west region) where I do store.loadData(RESPONSE_FROM_AJAX_CALL).

If i just define an url for the store, how and where does it load it? Does it do that on its own, or do i have to call load() at some point?
Also, you mentioned calling refresh. It's not clear if you mean refreshing the grid, which would also refresh/reload the store first, or the other way around, i mean reloading the store which automatically would refresh the grid?

cripkd
13 Aug 2009, 3:44 AM
Yeap, that works.
I added an url config option to the store, and instead of an ajax connection loading data to the store, as if the data would be static local data, i can no call load on it, and it uses a default http proxy to load the data.
That also provide the possibility to call reload after i save my new grid entry.
Nice :)

thtr4000
8 Dec 2009, 12:30 AM
Can you post code refesh store after add new items in grid.
I use window.opener but not run.

Can you help me?