DataTable renders an array of your own rows through a list of column definitions. Where Table takes cells that are already rendered, DataTable keeps the rows as data, so it can sort by the values rather than by the text on screen, select rows by id, and page through them. It draws the same table as Table.
DataTable is generic over the row type, so cell and sort receive your rows typed. A column without cell shows row[key]. Name the table with aria-label, or point aria-labelledby at a heading above it.
A sortable column's header is a button. Each press cycles ascending, descending and back to the rows' own order, and the sorted header carries aria-sort. Without a sort function the column compares row[key]: numbers as numbers, dates by time, text in natural order ("Item 2" before "Item 10"), with empty values last in both directions. Give the column a sort comparator, written ascending, when the key is not a field of the row or its values need their own order:
DataTable keeps the sort itself, starting from defaultSort, or follows sort and onSortChange when the host owns it. null is unsorted. A new sort returns to the first page.
selectable adds a checkbox column. The header checkbox selects or clears the rows on screen, and shows a mixed state when only some of them are selected; selection is kept across pages. getRowId gives each row the id that selection reports; without it a row's id field is used, or its index. getRowLabel names each row's checkbox for screen readers.
paginated shows the rows a page at a time with Pagination below; perPageOptions adds a page-size select.
searchable adds a search field above the table, and a column with a filter adds a select of its options. Both are 32px controls, the height of a small Button, so your own controls fit beside them in toolbar. DataTable keeps the search and the filters itself (from defaultSearch and defaultFilters), or follows search and filters with onSearchChange and onFiltersChange. filters is keyed by column: { status: "paid" }, or a list for a multiple filter. A new search or filter returns to the first page.
The search matches any column's row[key], ignoring case; pass matchSearch to search otherwise. A filter passes rows whose row[key] is the picked value (or holds it, for an array); give it a match function for anything else. When nothing matches, DataTable says so, with a button that clears the search and filters, instead of the no-data state; pass your own as noResultsState.
hide drops a column, header and cells, at a breakpoint and below: hide: { s: true }. It is CSS, so the server render is already right. Readers choose columns themselves from columnsMenu; columnVisibility with onColumnVisibilityChange puts that choice in your hands, to save it. Give a column a label when its header is not plain text, to name its filter and menu entry. Narrow this example to see Issued, then Customer, drop out.
Table takes the same hide on its headers.
When the server sorts and pages, pass the current page's rows with count, the number of rows on the server (or total, the number of pages). DataTable then neither sorts nor slices the rows: it reports onPageChange, onPerPageChange and onSortChange, and shows loading while you fetch. Give rows a getRowId here, since an index repeats from page to page.
With count or total the search and filters are the server's to apply: DataTable reports them and shows the rows you pass. Rather than one handler per piece, onQueryChange hands you the page, page size, sort, search and filters together, once per change, ready to fetch with. keepRowsWhileLoading keeps the last page on screen, dimmed, while the next one loads, so the table does not flash skeletons on every keystroke. Debounce the fetch if your API is slow to answer.
With no rows DataTable shows an empty state; pass your own as emptyState. While loading, skeleton rows stand in for the page (as many as perPage), the table is marked aria-busy, and sorting, selection and pagination are disabled.
stickyHeader keeps the header row in view while the rows scroll; pair it with maxHeight, which on DataTable caps the scroll area. striped, hoverable and compact work as on Table.