The choice depends on data volume, security and user experience. Client-side filtering (React filters data already loaded) - Pros: instant response, no extra requests, offline-friendly, simple backend. - Cons: only practical for small datasets (hundreds to a few thousand rows); large payloads slow the initial load and use memory on low-end devices; every row sent must be authorised for the user, because hidden rows are still visible in the network response. - Libraries: TanStack Table, AG Grid client-side row model. Server-side filtering (Spring Boot filters, sorts and paginates) - Pros: scales to millions of rows, small responses, the database uses indexes, and security filtering happens on the server. - Cons: a request per change and more API work. Server-side implementation in Spring Boot - Endpoint: GET /api/orders?status=SHIPPED&q=acme&sort=createdAt,desc&page=0&size=50 - Spring Data's Pageable and Page<T> handle paging and sorting; Specifications (JPA Criteria API) or Querydsl build dynamic filters safely with bound parameters — never concatenate user input into JPQL or SQL. - Whitelist sortable and filterable fields to prevent arbitrary sorting on unindexed columns. - For large tables, use keyset (cursor) pagination instead of deep OFFSET queries, and avoid expensive total counts when not needed (Slice<T> instead of Page<T>). - Add indexes for common filter and sort combinations; consider a search engine (Elasticsearch or OpenSearch) for full-text search. React side - Keep filter, sort and page state in the URL (query string) so it survives refresh and can be shared. - Debounce text inputs (about 300 ms) and cancel outdated requests (AbortController or TanStack Query, which also caches results and keeps the previous page visible while loading). - Show loading, empty and error states. Hybrid approach Server-side filtering for the main dataset, with client-side filtering only within the current page or for small reference lists (country or status dropdowns). Decision rule: if the full dataset is small, rarely changes and is fully visible to the user, client-side is fine; otherwise use server-side filtering.
Ravindra Wadile · · 0 likes