Is there a way to force a single row refresh with SlickGrid?

jbarlow picture jbarlow · Nov 15, 2012 · Viewed 7.9k times · Source

I have the amazing SlickGrid configured to access data asynchronously and post user changes back to the server asynchronously. In general terms, the server may modify a few fields of a row based on the user's changes. As such, after the row is updated I would like SlickGrid to refresh only that row without changing the rest of the view.

Does anyone know how to do this?

In my case, the field that changes on the server is a timestamp associated with the record that is updated by a database trigger. If the timestamp is out of date, the user has an old copy of data, and if they submit changes, they may overwrite a new copy. Since I can't find a way to trigger a refresh, the user cannot modify their own changes without refreshing the browser window (forcing a complete refresh).

Answer

njr101 picture njr101 · Nov 19, 2012

You should be able to do this using grid.invalidateRow() and grid.render(). SlickGrid will re-render the affceted rows (assuming they are displayed in the currently visible viewport) without refreshing the entire page.

// Mark row 42 as changed and re-render the display
grid.invalidateRow(42);
grid.render();

For an example check out SlickGrid Example 14. (Click the Start Simulation button to see it in action)