Compare server-side filtering with client-side filtering for a React data grid backed by ASP.NET Core.
Zomato · Full Stack Developer · 3-4-years · technical
Published
Year not specified · .NET, React, SQL
Community answers
Posted by wasAsked editorial collection
Filtering should normally happen server-side when the dataset is large, security-sensitive, paginated, or shared across users. The database can use indexes and return only authorized rows. Client-side filtering is reasonable for a small dataset already fetched for display.
Treat client filters as requests, never authorization. Accept an allow-listed filter model, validate ranges and sort fields, apply authenticated RestaurantId and OutletId first, project required columns, and cap page size. Prefer keyset pagination for deep or changing lists. Return filter metadata when it helps the UI, and preserve filters in the URL. Measure query plans and response sizes; moving a slow unindexed scan behind an API does not solve it.
Backbencher Developer · · 0 likes
The decision depends on data size, security and how the grid is used.
Client-side filtering (load everything once, filter in React):
- Pros: instant filtering and sorting, no extra requests, simple API.
- Cons: only works for small datasets (a few thousand rows), large initial payload, memory use on low-end devices, and you must still make sure the user is allowed to see every row you send.
Server-side filtering (React sends filters, sorting and page info to ASP.NET Core):
- Pros: scales to millions of rows, small payloads, the database uses indexes, and authorization is enforced on the server for every query.
- Cons: a request per change and more API design work.
A good server-side design:
GET /api/orders?status=Shipped&search=acme&sort=-createdAt&page=2&pageSize=50
- Validate and whitelist filter and sort fields; never build SQL from raw strings.
- Build an IQueryable in EF Core and apply Where/OrderBy/Skip/Take so filtering happens in SQL.
- Prefer keyset (cursor) pagination for large tables; OFFSET gets slower on deep pages.
- Return items plus total count or a next cursor.
- Add indexes for the common filter and sort columns.
On the React side:
- Keep filter state in the URL so it survives refresh and can be shared.
- Debounce text search (about 300 ms) and cancel stale requests with AbortController or a library such as TanStack Query.
- Show loading and empty states and keep the previous page visible while the next loads.
Many real apps use a hybrid: server-side filtering for the main grid, client-side filtering only within the currently loaded page or for small lookup lists.