()
| 12 | import { SortTableBasic } from "./examples/SortTableBasic"; |
| 13 | |
| 14 | export default function SortingRoute() { |
| 15 | return ( |
| 16 | <Box direction="column" gap={4}> |
| 17 | <Header section="Table" title="Sorting" /> |
| 18 | <div> |
| 19 | <code>Table</code> headers can be made sortable. Click a column header |
| 20 | below to sort by it; click it again to reverse the sort direction. |
| 21 | </div> |
| 22 | <Block className="p-0!" data-focus-within="bold"> |
| 23 | <div> |
| 24 | <SortTableBasic /> |
| 25 | </div> |
| 26 | </Block> |
| 27 | <div> |
| 28 | <code>Table</code> does not sort data itself. Instead, it tells you how |
| 29 | the data should be sorted, and renders the current sort state: |
| 30 | </div> |
| 31 | <ul className="list-disc pl-6 flex flex-col gap-1"> |
| 32 | <li> |
| 33 | <code>sort</code> is called when a sortable header is clicked (or |
| 34 | activated with the ENTER or SPACE key). It is passed the{" "} |
| 35 | <code>sortBy</code> (the clicked column's <code>dataKey</code>) and |
| 36 | the suggested <code>sortDirection</code>, as well as the column's{" "} |
| 37 | <code>defaultSortDirection</code> and the DOM <code>event</code>. Sort |
| 38 | your data accordingly, and update your state to re-render the table. |
| 39 | </li> |
| 40 | <li> |
| 41 | <code>sortBy</code> is the <code>dataKey</code> that data is currently |
| 42 | sorted by (if it is sorted at all). |
| 43 | </li> |
| 44 | <li> |
| 45 | <code>sortDirection</code> is the direction data is currently sorted |
| 46 | in (if it is sorted at all). |
| 47 | </li> |
| 48 | </ul> |
| 49 | <Code html={SortTableBasicJson.html} /> |
| 50 | <div> |
| 51 | Headers are only sortable if a <code>sort</code> function is provided. |
| 52 | Individual columns can opt out with the <code>disableSort</code> prop. A |
| 53 | column's <code>defaultSortDirection</code> (<code>"ASC"</code> by |
| 54 | default) controls the suggested direction when it is first clicked; |
| 55 | clicking it again suggests the opposite direction. See{" "} |
| 56 | <Link to="/table/column-props">Column props</Link> for more. |
| 57 | </div> |
| 58 | <SectionHeader>SortDirection</SectionHeader> |
| 59 | <div> |
| 60 | The <code>SortDirection</code> constant specifies which direction data |
| 61 | is sorted in: |
| 62 | </div> |
| 63 | <ul className="list-disc pl-6 flex flex-col gap-1"> |
| 64 | <li> |
| 65 | <code>SortDirection.ASC</code> (<code>"ASC"</code>) sorts items in |
| 66 | ascending order, from the lowest value to the highest (e.g. a-z, 0-9). |
| 67 | </li> |
| 68 | <li> |
| 69 | <code>SortDirection.DESC</code> (<code>"DESC"</code>) sorts items in |
| 70 | descending order, from the highest value to the lowest (e.g. z-a, |
| 71 | 9-0). |
nothing calls this directly
no outgoing calls
no test coverage detected