| 25 | ]; |
| 26 | |
| 27 | export const Example = (args: any) => { |
| 28 | let [sortDescriptor, setSortDescriptor] = useState({ |
| 29 | column: 'name', |
| 30 | direction: 'ascending' |
| 31 | }); |
| 32 | |
| 33 | let items = useMemo(() => { |
| 34 | let items = rows |
| 35 | .slice() |
| 36 | // @ts-ignore |
| 37 | .sort((a, b) => a[sortDescriptor.column].localeCompare(b[sortDescriptor.column])); |
| 38 | if (sortDescriptor.direction === 'descending') { |
| 39 | items.reverse(); |
| 40 | } |
| 41 | return items; |
| 42 | }, [sortDescriptor]); |
| 43 | |
| 44 | return ( |
| 45 | <Table |
| 46 | aria-label="Files" |
| 47 | {...args} |
| 48 | sortDescriptor={sortDescriptor} |
| 49 | onSortChange={setSortDescriptor} |
| 50 | className="w-100 max-w-full"> |
| 51 | <TableHeader> |
| 52 | <Column id="name" isRowHeader allowsSorting> |
| 53 | Name |
| 54 | </Column> |
| 55 | <Column id="type" allowsSorting> |
| 56 | Type |
| 57 | </Column> |
| 58 | <Column id="date" allowsSorting> |
| 59 | Date Modified |
| 60 | </Column> |
| 61 | </TableHeader> |
| 62 | <TableBody items={items}> |
| 63 | {(row: any) => ( |
| 64 | <Row> |
| 65 | <Cell>{row.name}</Cell> |
| 66 | <Cell>{row.type}</Cell> |
| 67 | <Cell>{row.date}</Cell> |
| 68 | </Row> |
| 69 | )} |
| 70 | </TableBody> |
| 71 | </Table> |
| 72 | ); |
| 73 | }; |
| 74 | |
| 75 | Example.args = { |
| 76 | onRowAction: null, |