()
| 14 | import { AutoSizer } from "react-virtualized-auto-sizer"; |
| 15 | |
| 16 | function Example() { |
| 17 | const [sortBy, setSortBy] = useState<TableProps["sortBy"]>("index"); |
| 18 | const [sortDirection, setSortDirection] = useState< |
| 19 | TableProps["sortDirection"] |
| 20 | >(SortDirection.ASC); |
| 21 | |
| 22 | // Table does not sort data itself; it only tells you how to sort it |
| 23 | const sortedList = useMemo( |
| 24 | () => sortList(list, sortBy, sortDirection), |
| 25 | [sortBy, sortDirection] |
| 26 | ); |
| 27 | |
| 28 | return ( |
| 29 | <AutoSizer |
| 30 | renderProp={({ width }) => |
| 31 | width !== undefined ? ( |
| 32 | <Table |
| 33 | headerHeight={36} |
| 34 | height={250} |
| 35 | rowClassName="border-b border-ink/10" |
| 36 | rowCount={sortedList.length} |
| 37 | rowGetter={({ index }) => sortedList[index]} |
| 38 | rowHeight={30} |
| 39 | sort={({ sortBy, sortDirection }) => { |
| 40 | setSortBy(sortBy); |
| 41 | setSortDirection(sortDirection); |
| 42 | }} |
| 43 | sortBy={sortBy} |
| 44 | sortDirection={sortDirection} |
| 45 | width={width} |
| 46 | > |
| 47 | <Column dataKey="index" label="Index" width={80} /> |
| 48 | <Column |
| 49 | dataKey="name" |
| 50 | // Sort descending when this column is first clicked |
| 51 | defaultSortDirection={SortDirection.DESC} |
| 52 | label="Name" |
| 53 | width={120} |
| 54 | /> |
| 55 | <Column |
| 56 | dataKey="random" |
| 57 | // This column can't be sorted |
| 58 | disableSort |
| 59 | flexGrow={1} |
| 60 | label="Description" |
| 61 | width={200} |
| 62 | /> |
| 63 | </Table> |
| 64 | ) : null |
| 65 | } |
| 66 | /> |
| 67 | ); |
| 68 | } |
| 69 | |
| 70 | function sortList( |
| 71 | list: ListItem[], |
nothing calls this directly
no test coverage detected