
Your task is to build a DataTable that supports sorting and pagination, and where each column can optionally display a filter input directly within its header. These filter inputs let users narrow down visible rows by entering specific criteria for each column. Filters can be combined—only rows that satisfy all active filter conditions should be displayed. A React DataTable with column filters builds on Array.prototype.filter() for each active condition.
React DataTable Column Filtering Rules
- String columns: Show a text input. Rows should be included if their value for that column contains the entered text (case-insensitive).
- Numeric columns: Show two number inputs labeled “Min” and “Max.” Rows should be included only if their value falls within the entered range (inclusive). If either min or max is left blank or invalid, ignore that boundary.
- If a filter field is empty or invalid, do not apply that filter to the data.
- All filters are cumulative—rows must match every active filter to be shown.
- When no rows match, show an empty-state message such as “No data found”.
Component Flexibility
- The DataTable should remain fully reusable. You must not hardcode any data or filter logic—configuration must come from the
columns array and data. The table is rendered without arguments, so default them to the provided columns and data constants (and pageSize to 5).
- Clicking a sortable column header sorts by that column (ascending first).
- Show 5 rows per page with “Prev” and “Next” buttons.
- Filtering must work in combination with sorting and pagination; users should be able to filter, sort, and page through data at the same time.
- The filter inputs should be visually integrated into the table header and styled for clarity and usability.
Examples
- Typing "alex" into the "Name" filter should instantly show only users whose names contain "alex" (e.g., "Alexander Hall").
- Entering Min = 30 and Max = 40 in the "Age" filter should only show users whose ages are between 30 and 40.
- Combining filters (e.g., Name="an", Age Min=35) narrows results to users matching both conditions.
Accessibility
- All filter inputs and controls must be keyboard accessible and have clear labels or placeholders.
Design Goal
Your solution should deliver a fast, intuitive, and visually appealing experience for exploring tabular data. Think about how real-world productivity apps handle table filtering—aim for that level of polish!
How your solution is tested
The tests type into your filters, click headers and buttons, and read the text on the screen, like a real user would. You don’t need test ids, specific class names, or an exact HTML structure. They only check that:
- Each text filter has a label,
aria-label, placeholder, or name containing its column name (e.g. aria-label="Filter Name", "Filter Occupation").
- The Age inputs are labelled with “Min” and “Max”.
- The sortable header is clickable (a button, or any element with a click handler) and its text starts with the column name.
- Page 1 shows the first 5 rows of the provided data; a “Next” button shows the next 5.
- Rows on the current page appear in sorted order, and the empty state contains “No data” / “No results”. Capitalization doesn’t matter.