# RSC Mode Grouping Overview

In server-side scenarios, the grouping logic works similarly to [grouping in the client mode of the Grid](https://www.telerik.com/kendo-react-ui/components/grid/grouping), but with [server actions](https://www.telerik.com/kendo-react-ui/components/grid/rsc-mode/server-actions). When the user modifies the grouping state or expand a group, the server is responsible for saving and managing the grouped data.

<CtaPanelOverview></CtaPanelOverview>

When grouping changes occur, the [`onGroupChange`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops#ongroupchange) 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. This ensures that grouping state is handled on the server side.

Since the grouping state is stored on the server (such as in cookies), you must ensure proper state management to maintain consistent grouping across page reloads.

```tsx
const onGroupChange = async (event: ServerEvent<GridGroupChangeEvent>) => {
    'use server';
    const groupedState = event.group;

    cookies().set(TAG, JSON.stringify(groupedState)); // Save current grouping state
};

return <Grid onGroupChange={onGroupChange} groupable={true} dataItemKey={dataItemKey}></Grid>;
```

Below you can see an example of handling grouping changes on the server to maintain consistent state across reloads.

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

## Suggested Links

* [KendoReact Grid Grouping Documentation](https://www.telerik.com/kendo-react-ui/components/grid/grouping)
* [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)
