> ## Documentation Index
> Fetch the complete documentation index at: https://nestjs-query.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Paging and Sorting

## Offset paging

Offset paging is the default REST strategy. The endpoint accepts:

* `limit`: maximum number of records to return. The default is `25` and the default maximum is `50`.
* `offset`: zero-based number of records to skip. The default is `0`.

```http theme={null}
GET /todo-items?limit=25&offset=50
```

```json theme={null}
{
  "pageInfo": {
    "hasNextPage": false,
    "hasPreviousPage": true
  },
  "nodes": []
}
```

Configure paging on the DTO or endpoint:

```ts theme={null}
import { SortDirection } from '@ptc-org/nestjs-query-core'
import { PagingStrategies, QueryOptions } from '@ptc-org/nestjs-query-rest'

@QueryOptions({
  pagingStrategy: PagingStrategies.OFFSET,
  defaultResultSize: 20,
  maxResultsSize: 100,
  enableTotalCount: true
})
export class TodoItemDTO {}
```

When `enableTotalCount` is `true`, the connection also contains `totalCount`. Counting may add a database query, so enable it only when clients need it.

## No paging

Use `PagingStrategies.NONE` to return all matching records as a JSON array:

```ts theme={null}
{
  DTOClass: TodoItemDTO,
  EntityClass: TodoItemEntity,
  pagingStrategy: PagingStrategies.NONE
}
```

```json theme={null}
[
  { "id": 1, "title": "Write docs", "completed": false },
  { "id": 2, "title": "Review docs", "completed": true }
]
```

Use this strategy only for bounded collections.

## Sorting

REST sorting is currently configured on the server through `defaultSort`; generated endpoints do not expose a client-controlled sort parameter.

```ts theme={null}
@QueryOptions({
  defaultSort: [
    { field: 'completed', direction: SortDirection.ASC },
    { field: 'created', direction: SortDirection.DESC }
  ]
})
export class TodoItemDTO {}
```

Always add a stable tie-breaker (commonly the ID) when records can share the same sort value, especially when using offset paging.
