question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sorted and Searchable DataTable with Pagination from backend

See original GitHub issue

What package(s) are you using?

  • carbon-components
  • carbon-components-react

Summary

The current DataTable is suitable for situations where you can download the entire dataset and use the built-in sorting mechanism. However, with large enough datasets, you must stream the data in a page at a time to prevent overloading either the client or the server. This is incompatible with the current built-in sorting mechanism, because it only sorts the page. It’s preferable to simply retrieve the current sort state, i.e.

const [sortHeader, setSortHeader] = useState('created');
const [sortDirection, setSortDirection] = useState('None');

const [page, setPage] = useState(1);
const [pageSize, setPageSize] = useState(10);
const start = pageSize * (page - 1)
const end = start + pageSize
const { data } = useSWR([start, end, sortHeader, sortDirection, 'myDataset'], getDataset, {suspense: true});
<DataTable 
    onSortChanged={(key: string, direction: 'ASC' | 'DESC' | 'None') => setSortHeader(key); setSortDirection(direction)}
    ...
/>

However, it doesn’t seem to be possible to do so. A similar story applies to search. What is the best way to scale the DataTable component so that its various functionality works well when populated by a backend that can perform its own search/sort/etc?

Relevant information

For the early stages of my work, I intend to just retrieve the entire dataset since it is still small. In the future, a feature may end up being requested that requires this functionality.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Daveianocommented, Dec 16, 2021

This is indeed solved with a custom state manager, here is an actual example: https://github.com/carbon-design-system/carbon/tree/main/packages/react/examples/custom-data-table-state-manager

0reactions
emyarodcommented, Dec 16, 2021

most likely you would need to implement this with a custom state manager, meaning you would be implementing that logic using Carbon table primitives like Table, TableHead, TableRow, etc. rather than using the built in state manager in DataTable, if that makes sense

updated link to reflect master to main branch rename

Read more comments on GitHub >

github_iconTop Results From Across the Web

Paginate, search, and sort combined data in DataTables ...
Paginate, search, and sort combined data in DataTables Editor with ASP. ... Our priority is to activate DataTables Editor in the backend controller...
Read more >
DataTables AJAX Pagination with Search and Sort - PHP
DataTables AJAX Pagination with Search and Sort – PHP ... DataTables is a jQuery plugin that makes it easier to add pagination on...
Read more >
Datatable Pagination, Sorting and Search - Server Side (PHP ...
This is jquery datatable tutorial to add sorting,searching and pagination into HTML table.We are using PHP and MySQL to featch records.
Read more >
Data table with sorting, pagination, and filtering. - StackBlitz
Data table with sorting, pagination, and filtering. ... Set the paginator and sort after the. import. Enter to Rename, Shift+Enter to Preview.
Read more >
Angular 8 Data Tables with sorting, pagination, and filtering ...
Angular Material Data Table - Paging, Sorting, Filtering.In this Angular 8 tutorial will get an understanding of Angular Data Tables, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found