PluginProbe
Code Snippets / 4.0.0-beta.2
Code Snippets v4.0.0-beta.2
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
← All changes | js/components/common/ListTable/ListTable.tsx +12 -2 3.10.0 → 4.0.0-beta.2 View file →
@@ -128,8 +128,11 @@
128 128 ListTableRowsProps<T, K> {
129 129 items: T[]
130 130 beforeTable?: ReactNode
131 131 selectAllControl?: boolean
132 +
133 + /** Column and direction to sort by before the reader touches a heading. */
134 + initialSort?: { columnId: string, direction: ListTableSortDirection }
132 135 }
133 136
134 137 export const ListTable = <T, K extends Key, A extends string = never>({
135 138 items,
@@ -135,15 +138,22 @@
135 138 items,
136 139 getKey,
137 140 totalPages,
138 141 pageSearchParam = 'paged',
142 + initialSort,
139 143 ...tableProps
140 144 }: ListTableProps<T, K, A>) => {
141 - const [sortColumn, setSortColumn] = useState<ListTableColumn<T>>()
145 + const [sortColumn, setSortColumn] = useState<ListTableColumn<T> | undefined>(
146 + () => initialSort
147 + ? tableProps.columns.find(column => column.id === initialSort.columnId && column.sortedValue)
148 + : undefined
149 + )
142 150 const [currentPage, setCurrentPage] = useState(
143 151 () => pageSearchParam && Number(fetchQueryParam(pageSearchParam)) || 1
144 152 )
145 - const [sortDirection, setSortDirection] = useState<ListTableSortDirection>('asc')
153 + const [sortDirection, setSortDirection] = useState<ListTableSortDirection>(
154 + () => initialSort?.direction ?? 'asc'
155 + )
146 156
147 157 const visibleItems: T[] = useMemo(
148 158 () => pageItems(sortTableItems(items, sortColumn, sortDirection), { currentPage, totalPages }),
149 159 [items, sortColumn, sortDirection, currentPage, totalPages])