Remote Data Table: Server-Side Pagination, Sorting & Debounced Search
In enterprise applications with thousands or millions of records, loading the entire dataset into the client browser is unfeasible. This recipe demonstrates the recommended architecture for implementing server-side pagination, remote sorting, and real-time debounced search using PxDataTable.
Interactive Demonstration
Interact with the table below. The data is fetched with a simulated 400ms network delay, displaying the loading skeleton state (loading), preserving query parameters, and dynamically updating total count and pages.
User | Role / Position | Department | Status | Sales ($) |
|---|---|---|---|---|
No data available | ||||
Step-by-Step Implementation
1. State Contract Definition
To synchronize the table view with the server, maintain dedicated reactive variables:
currentPage: Current active page (1-indexed).pageSize: Number of rows per page (10,25,50).sortField&sortOrder: Active sorting column and direction (1for ascending,-1for descending).isLoading: Triggers the built-in skeleton loading state ofPxDataTable.
2. Avoid Redundant Queries with Debounce
When typing in the search input, never dispatch an HTTP request on every keystroke. Use a timer or useDebounceFn from @vueuse/core with a standard 300ms delay:
import { useDebounceFn } from '@vueuse/core'
const debouncedSearch = useDebounceFn((term: string) => {
searchQuery.value = term
currentPage.value = 1 // Reset to first page when query changes
loadData()
}, 300)3. Listening to @page and @sort Events
PxDataTable emits clean payloads whenever the user interacts:
@page="{ page, rows }": When changing page number or changing rows per page.@sort="{ field, order }": When clicking any header withsortable: true.
Request Cancellation (AbortController)
If users rapidly type or switch pages, utilize an AbortController to abort any pending in-flight HTTP request to prevent race conditions.