Playground API
DocsStatsBlogStudio
Documentation Tree
Technical BlogFeature Deep Dives
  • Introduction
  • Quickstart
    5 min
  • How It Works
  • Recipes & Cookbooks
  • Platform Comparisons
  • Real-World Showcase
  • Interactive Studio
    Studio
  • GraphiQL IDE
    IDE
  • Session Quotas & Activity
  • Network Chaos Simulator
  • Atomic Sandbox Reset
  • Overview & Models
    Hub
  • Users Resource
  • Posts Resource
  • Comments Resource
  • Todos Resource
  • Custom Collections
    Custom
  • Multipart File Uploads
    Upload
  • Dynamic SVG Avatars
    SVG
  • Image Thumbnails
    CDN
  • Relational Filtering
  • Full-Text Search
  • Dynamic Sorting
  • Offset Pagination
  • Cursor Pagination
    Scroll
  • CSV & Excel Export & Import
    IO
  • Custom Collections
    CRUD
  • Overview & Architecture
    Hub
  • JWT Auth Flow
  • Refresh Token Rotation
    Mutex
  • RBAC Permission Matrix
    Roles
  • Expiry Simulation
  • Clock Skew Drift
  • Password Recovery Loop
  • Dual-Mode Sandboxing
  • GraphiQL IDE
    IDE
  • Relational Queries
  • Stateful Mutations
  • Realtime Subscriptions
  • Overview & Flowcharts
    Hub
  • Hosted Checkout
    Stripe
  • Payment Intents API
  • 3DS Challenge Modal
    Modal
  • Customers Vault
  • Charges & Refunds
  • Test Cards Catalog
  • Overview & Channels
    Hub
  • Virtual Email Mailbox
    Mailtrap
  • Virtual SMS Terminal
    Phone
  • In-App Notifications
  • Message Dispatcher
  • Realtime Studio
    Studio
  • Native WebSocket (/ws)
  • Socket.io Gateway
  • Presence & Echo Bot
  • Server-Sent Events (SSE)
    SSE
  • Analytics Telemetry
  • Webhook Subscriptions
  • HMAC SHA-256 Signatures
  • Delivery Logs
  • Manual Retry Simulator
  • Network Latency Delay
  • HTTP Status Codes
  • Rate-Limit Simulator
    429
  • Flaky Network & Jitter
    Chaos
  • Session Quotas & Activity
  • JSON Snapshots
    JSON
  • Headless CI/CD Testing
    CI
  • Mobile QR Code Sync
  • System Metrics & Health
  • Atomic Sandbox Reset
  • Official TypeScript SDK
  • Multi-Language Generators
  • DevTools Extension
  • OpenAPI 3.1 Spec
    JSON
  • Postman Collection v2.1
  • Bruno Collection
  • Insomnia Workspace
  • TypeScript .d.ts
    .d.ts
  • AI Prompt Rules
    Rules
  • Context Index (llms.txt)
  • Full Schema (llms-full.txt)
  • Manifest (product.json)
  • All Feature Articles
    Blog
  • React CRUD Without Backend
    Deep Dive
  • Why Static APIs Fail
  • Mocking Stateful Auth
  • WebSockets & SSE Guide
Technical Blog
Articles

In-depth articles explaining stateful mock APIs, WebSockets, payments, and frontend resilience.

Read Articles
PreviousFull-Text Search
NextOffset Pagination
Data & Query Engine

Dynamic Multi-Type Sorting

Order API responses by any numerical, string, or boolean field using _sort and _order. Values are sorted with type-aware comparison, ensuring proper numeric order instead of alphabetical bugs.

Live Sorting Playground

Customize sort target and direction to test across collections:

Direction:
Sorting posts by id in desc order.GET /posts?_sort=id&_order=desc
Method: GET

Live Request Console

GET
response.json
1
{
2
// Click "Send" above to execute this request against the live server.
3
}

Type-Aware Sort Evaluation

Many mock servers fail by treating all fields as strings, causing 10 to sort before 2. Playground inspects underlying data types:

Data TypeSort StrategyASC Order ExampleDESC Order Example
Numeric (ID, Price, Stock)Numeric comparison (a - b)1, 2, 9, 10, 100100, 10, 9, 2, 1
String (Title, Name, Email)Case-insensitive localeCompareAlice, Bob, CharlieCharlie, Bob, Alice
Boolean (Completed, InStock)Falsy values first in ASCfalse, false, true, truetrue, true, false, false

Client Integration Recipes

DataGrid and table sorting patterns for React and modern web apps:

components/DataTable.tsx
1
// components/DataTable.tsx
2
import { useState } from 'react';
3
import { useQuery } from '@tanstack/react-query';
4
5
interface SortingState {
6
field: string;
7
order: 'asc' | 'desc';
8
}
9
10
export function DataTable() {
11
const [sorting, setSorting] = useState<SortingState>({
12
field: 'id',
13
order: 'desc'
14
});
15
16
const { data, isLoading } = useQuery({
17
queryKey: ['posts', sorting],
18
queryFn: async () => {
19
const res = await fetch(
20
https://playground.nileslabs.com/api/v1/posts?_sort=${sorting.field}&_order=${sorting.order}`,
21
{ credentials: 'include' }
22
);
23
if (!res.ok) throw new Error('Failed to fetch sorted records');
24
return res.json();
25
}
26
});
27
28
const toggleSort = (field: string) => {
29
setSorting((prev) => ({
30
field,
31
order: prev.field === field && prev.order === 'asc' ? 'desc' : 'asc'
32
}));
33
};
34
35
return (
36
<table>
37
<thead>
38
<tr>
39
<th onClick={() => toggleSort('id')} className="cursor-pointer">
40
ID {sorting.field === 'id' && (sorting.order === 'asc' ? '▲' : '▼')}
41
</th>
42
<th onClick={() => toggleSort('title')} className="cursor-pointer">
43
Title {sorting.field === 'title' && (sorting.order === 'asc' ? '▲' : '▼')}
44
</th>
45
</tr>
46
</thead>
47
<tbody>
48
{data?.data?.map((item: any) => (
49
<tr key={item.id}>
50
<td>{item.id}</td>
51
<td>{item.title}</td>
52
</tr>
53
))}
54
</tbody>
55
</table>
56
);
57
}
Next Query Feature

Offset-Based Pagination

Related Query Feature

Cursor-Based Pagination