LyteNyte Grid logo for light mode. Links back to the documentation home page.
Server Data Loading

Cell Editing Server Data

You can edit server-side data through the LyteNyte Grid server data source. This allows updating cell values and synchronizing those updates with the server.

This guide assumes familiarity with LyteNyte Grid's cell editing capabilities. If not, see the Cell Editing guide. The content here focuses on handling cell updates through the server data source.

Editing Data

LyteNyte Grid's useServerDataSource hook accepts a callback for the cellUpdateHandler property. This handler is called when a cell edit occurs in the grid and is responsible for sending the update request to the server. It runs asynchronously, and once the update completes, it's the developer's responsibility to refresh the grid data, typically by calling the server data source's refresh method.

The example below demonstrates this. You can edit any cell value (by double clicking on the cell); after committing the change, it won't update immediately but will refresh shortly to show the new value. This behavior isn't ideal, which is why the next section explains how to optimistically update the client value so changes appear instantly.

Edit Data Async

The example implements a basic update handler. In most cases, your update logic should look similar to the following:

cellUpdateHandler: async (updates) => {
// send update to server
await handleUpdate(updates);
// refresh after the update
ds.refresh();
};

Optimistic Update For Instant Feedback

The example above isn't ideal for many use cases. The main issue is that cell updates aren't reflected immediately. LyteNyte Grid's server data source provides an optimistic update flag that applies cell updates directly on the client. Enabling this flag assumes the server update will succeed. The cellUpdateOptimistically property makes cell updates apply instantly on the client, but remember that this change is client only. Developers must still implement the cellUpdateHandler function and handle any errors that occur when sending updates to the server.

Edit Data Async With Optimistic Updates

With optimistic updates enabled, you can skip the refresh step if the applied update matches the expected server value. The server update logic now looks similar to:

cellUpdateHandler: async (updates) => {
// send update to server
await handleUpdate(updates);
},
cellUpdateOptimistically: true,

Next Steps