# RSC Mode Sorting Overview

When the Grid is used in server mode, sorting is configured and behaves like the [sorting in the client mode of the Grid](https://www.telerik.com/kendo-react-ui/components/grid/sorting), but it relies on [server actions](https://www.telerik.com/kendo-react-ui/components/grid/rsc-mode/server-actions). When a user sorts a column, the server handles storing and processing the sorting rules.

<CtaPanelOverview></CtaPanelOverview>

Each time a sorting action is performed, the [`onSortChange`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops#onsortchange) and the [`onDataStateChange`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops#ondatastatechange) callbacks are triggered. In the RSC mode of the Grid, this callback must be marked as `async` and include `'use server'` at the top to ensure proper execution on the server.

The sorting state has to be managed on the server (for example, in cookies) therefore you should persist the sorting state correctly to maintain the user’s preferences across page reloads.

```tsx
const onSortChange = async (event: ServerEvent<GridSortChangeEvent>) => {
    'use server';
    const sortState = event.sort;

    cookies().set(TAG, JSON.stringify(sortState)); // Store the current sorting state
};

return <Grid onSortChange={onSortChange} sortable={true} dataItemKey={dataItemKey}></Grid>;
```

Here is an example demonstrating how to manage sorting state on the server for consistent user experience.

[Demo Source](https://demos.telerik.com/kendo-react-ui/grid/server-components/sorting/source.txt)

## Suggested Links

* [KendoReact Grid Sorting Documentation](https://www.telerik.com/kendo-react-ui/components/grid/sorting)
* [KendoReact Grid RSC Mode Server Actions](https://www.telerik.com/kendo-react-ui/components/grid/rsc-mode/server-actions)
* [КendoReact Grid RSC Mode Overview](https://www.telerik.com/kendo-react-ui/components/grid/rsc-mode)
* [Getting Started with КendoReact Grid RSC Mode](https://www.telerik.com/kendo-react-ui/components/grid/getting-started/get-started-rsc)
