简体   繁体   中英

Dojo DataGrid how to notify view that data has changed on the server?

how do I notify dojox.grid.DataGrid that data has changed in the store / on the server ?

I'm using dojox.data.QueryReadStore with DataGrid.

For example I want DataGrid to reload from server one row that I know has changed.

Thanks for help

Depending on IF you are caching or not the answer will be different. Most probably you'll end up doing something like a fetch with query : "?id=" + yourId + "&time=" + new Date().getTime() Reason being an Item cached is pretty much cached for the store's lifespan. The only way to force reload on the server is to use a different query (at least it's the case for the JsonRestStore). Maybe QueryReadStore is more clever and can systematically reload from server when using some functions.

Good old date trick to force reload :)

So if I understood your question right, you want to push the server state change to the client, right? So, a row has been changed on the server, you want to reflect that change automatically on the datagrid without any user intervention (datagrid should get re-loaded with the updated data)

This will require either polling or a server side push mechanism (such as cometd or html5 websocket)

Also, do you need to use queryreadstore (QRS) or a simpler itemfilewritestore (IFWS) will do? The reason I ask is QRS is useful for things like paging and lazy loading, but it adds complexity, especially for your usecase, since the row that changed might not be in the user's current view (assuming you want to show the row that changed).

If you can use qn itemfilewritestore, then, once you have a JS function invoked for this server side change (using one of the mechanism above), just update your store with this data value - the dojo datagrid will automatically get updated (dojo takes care of updating the rendered datagrid whenever the store data changes). See Add a row in Dojo datagrid for an example of how to manipulate the store.

If you must use QRS, there are 2 usecases, one is when the row inserted is in the currently visible dataset (in which case you need to re-issue the query) and another is when the new row is outside the currently displayed dataset (in which case the paging action from the user will automatically reflect the change in the row)

hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM