# Server-side row model

In this model, the server calculates grouping and pivots and supplies rows for each expanded group path. Its data responsibilities differ from grouping already loaded local rows with groupBy.

Canonical: https://grid.syidax.com/docs/features/server-side-row-model/

<a id="understand"></a>

## How it works and when to use it

serverSideDatasource.getRows receives the request and success/failure callbacks as separate arguments. Do not confuse it with params.success in the Infinite datasource.

Using this feature in a product requires the Pro package and a valid license. Matching setting names do not enable Pro features in Community.

In the code, grid is the Grid element prepared in the installation chapter. Check each example's data and settings, and implement the app functions and server endpoints for your project.

- [Installation and integration · Shared sample data](https://grid.syidax.com/docs/guides/getting-started.md)

<a id="example-1"></a>

## Example 1. Connect group requests

Prepare the server to interpret group paths, filters, and sorting and return rows and rowCount.

```javascript
grid.serverSideDatasource = { getRows: async (request, success, fail) => {
  try {
    const response = await fetch('/api/orders/groups', { method: 'POST',
      headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(request) });
    if (!response.ok) throw new Error('Query failed');
    success(await response.json());
  } catch { fail(); }
}};
```

Verify the result: Initially the server supplies top-level data; expanding a group requests data for that path. Review ServerSideGetRowsParams and Result as part of the server contract.

<a id="example-2"></a>

## Example 2. Selection with partially loaded data

Use server selection state to include orders that have not yet been downloaded.

```javascript
console.log(await grid.getServerSideSelectionState());
console.log(await grid.getServerGroupSelectionState());
```

Verify the result: Distinguish displayed row IDs from server-wide selection rules. Your app's bulk-operation API must understand those rules too.

<a id="example-3"></a>

## Example 3. Inspect caches and processing results

When an expanded group looks empty, inspect which stores have loaded.

```javascript
console.log(await grid.getServerSideStoreState());
console.log(await grid.getServerPivotResultColumns());
```

Verify the result: Inspect group store state separately from server-supplied pivot columns. Also check that server aggregate column names match the response data keys.

<a id="pitfalls"></a>

## Combining features and troubleshooting

Do not use regular client applyTransaction to change all unloaded server rows. Use server changes and the server-specific transaction or requery flow.

Distinguish group counts from leaf order counts and pivot result columns from source columns. An incorrect rowCount for an expanded path also affects loading and selection.

<a id="related-api"></a>

## APIs used by this feature

- [serverSideDatasource](https://grid.syidax.com/docs/options/serverSideDatasource.md) — Data provider for a row model where the server handles sorting, filtering, grouping, and related requests.
- [serverSideGroupCols](https://grid.syidax.com/docs/options/serverSideGroupCols.md) — Columns grouped on the server, ordered from outermost group inward. An empty array represents flat data.
- [serverSideTransactionWaitMs](https://grid.syidax.com/docs/options/serverSideTransactionWaitMs.md) — Delay for batching asynchronous server row transactions.
- [getServerSideSelectionState](https://grid.syidax.com/docs/methods/getServerSideSelectionState.md) — Reads select-all conditions and exception IDs for the flat server row model. Reports a model mismatch for grouped models.
- [getServerGroupSelectionState](https://grid.syidax.com/docs/methods/getServerGroupSelectionState.md) — Reads hierarchical select-all and exception state for the grouped server row model.
- [setServerSideSelectionState](https://grid.syidax.com/docs/methods/setServerSideSelectionState.md) — Replaces select-all conditions and exception IDs in the flat server row model.
- [setServerGroupSelectionState](https://grid.syidax.com/docs/methods/setServerGroupSelectionState.md) — Replaces hierarchical selection state in the grouped server row model.
- [selectAllServerSide](https://grid.syidax.com/docs/methods/selectAllServerSide.md) — Sets server-wide selection conditions without materializing every server row in memory.
- [selectServerGroupChildren](https://grid.syidax.com/docs/methods/selectServerGroupChildren.md) — Selects or deselects server descendants beneath a group-key path.
- [refreshServerSide](https://grid.syidax.com/docs/methods/refreshServerSide.md) — Refetches the specified server store scope and returns the result.
- [applyServerSideTransaction](https://grid.syidax.com/docs/methods/applyServerSideTransaction.md) — Applies row changes to the server row model's cache, separately from saving server source data.
- [applyServerSideTransactionAsync](https://grid.syidax.com/docs/methods/applyServerSideTransactionAsync.md) — Queues a server row transaction asynchronously. Queue acceptance differs from final application.
- [flushServerSideAsyncTransactions](https://grid.syidax.com/docs/methods/flushServerSideAsyncTransactions.md) — Processes pending server row transactions and returns a completion report.
- [getServerSideStoreState](https://grid.syidax.com/docs/methods/getServerSideStoreState.md) — Reads server store paths, states, and block caches. Assess loading through block counts and complete as well as state names.
- [getServerPivotResultColumns](https://grid.syidax.com/docs/methods/getServerPivotResultColumns.md) — Reads the server-supplied pivot result column model. Distinguish stale metadata from absent metadata.
- [auditServerPivotResultColumns](https://grid.syidax.com/docs/methods/auditServerPivotResultColumns.md) — Checks whether server pivot column IDs used for charts, export, or restoration still exist in the current model.
- [serverStoreUpdated](https://grid.syidax.com/docs/events/serverStoreUpdated.md) — Emitted when a server row store refreshes. Inspect its path and cache state.

<a id="next"></a>

## Related reading

- [How rows, columns, and IDs relate](https://grid.syidax.com/docs/guides/concepts.md)
- [Connect results and events](https://grid.syidax.com/docs/guides/data-event-access.md)
- [Explore in Features](https://grid.syidax.com/grid/server-side-row-model) — The guide describes which interactions are available to try.
