Server-side CRUD Operations
Learn how to perform CRUD operations using the Server-side Row Model.
Server-side Changing Data
Data is read back from the server side in blocks. This is similar to paging in other data-grids. This comes with one restriction - if the data is changing such that the data in each block changes, then the Server-side row model will get the incorrect rows. For example consider the following scenario:
- The grid asks for rows 0 to 99 (ie first block of 100 rows) and these get read from a database.
- Another application inserts a row at index 50.
- The grid asks for rows 100 to 199 (the second block of 100 rows) and again these get read from the database.
For this reason it is best use Server-side row model on data that is not changing, or a snapshot of the data.
Updating Row Data
It's possible to directly update row data without having to fetch data from the server.
The following code snippet outlines the general approach; iterate through all loaded row nodes and then update
them directly using rowNode.setData(data):
The example below shows this in action where the following can be noted:
- Update Selected Rows - will update the medal count directly on the row nodes and then invoke the mock server with the updated rows.
- Purge Caches - will clear all loaded data and force a reload. Notice that the previously updatad data will be returned from the server.
CRUD
The Server-side Row Model acts as a cache against the original store of data which typically resides on the server-side of an application. To add or remove records, the pattern is to update the original data set (typically on the server) and then get the Server-side Row Model to refresh.
The example below shows this in action where the following can be noted:
- The Add Row will add a row before the currently selected row.
- The Remove Row will remove the currently selected row.
- All operations are done outside of the grid and the grid is then told to refresh.