RSC Mode Server ActionsPremium
The RSC architecture introduces server actions
, which are seamlessly integrated in the server mode of the KendoReact Grid.
Server-actions compatibility allows passing functions to the component's callbacks, such as onDataStateChange
or onItemChange
, enabling the execution of custom server-side logic.
Available Server Actions
In the server mode of the Grid, the events fall into two categories:
- Data state change related events:
onFilterChange
onSortChange
onPageChange
onGroupChange
onDataStateChange
—triggered when either one of theonFilterChange
,onSortChange
,onPageChange
oronGroupChange
events occurs.
- Grid state operation related events:
Server Actions Configuration
To use event handlers on a server page, you can use the same setup as you would for a Grid on a client page. The key differences are:
- Event handlers must be marked as
async
and include'use server'
at the top. - Non-serializable event arguments should be wrapped inside a
ServerEvent<T>
type to ensure compatibility.
Client event arguments such as
nativeEvent
,syntheticEvent
,target
,targetEvent
, andfocusElement
cannot be serialized to the server and will always beundefined
.
Here is an example of a server action managing the Grid’s data state:
const onDataStateChange = async (event: ServerEvent<GridDataStateChangeEvent>) => {
'use server';
cookies().set(TAG, JSON.stringify(event.dataState)); //save state
};
return <Grid onDataStateChange={onDataStateChange} dataItemKey={dataItemKey}></Grid>;
Limitations
Client-only Events
There are some current events of the Grid that only make sense in a client scenario. As a result, the following events will not be triggered when the Grid is used as a server component: