Currently when you create a Table in northstar, the table is sorted by the first column by default.
I would like to create a full data table but I want the flexibility to sort by a column of my choosing. In my scenario, I have a table with 2 columns; a name and timestamp. I want the name to be the first column and the timestamp to be the second column, however, I want the table to be sorted by timestamp in descending order when the table is first shown.
This is how it is currently implemented in packages/ui/src/components/Table/components/FullDataTable/index.tsx:
const {...} = useCollection(allItems, {
...
sorting: {
defaultState: { sortingColumn: columnDefinitions[0] }
}
}
Proposed solution
Allow for 2 extra optional props on FullDataTable:
defaultSortColumn?: string;
defaultSortIsDescending?: boolean;
Update logic in FullDataTable to use these props and fall back to current functionality if the optional props are not provided
// use provided sort column, otherwise fall back to using first column
const sortingColumn = defaultSortColumn ?
columnDefinitions.find((col) => col.sortingField === defaultSortColumn)!
: columnDefinitions[0];
const {...} = useCollection(allItems, {
...
sorting: {
defaultState: { isDescending: defaultSortIsDescending, sortingColumn },
}
}
Currently when you create a Table in northstar, the table is sorted by the first column by default.
I would like to create a full data table but I want the flexibility to sort by a column of my choosing. In my scenario, I have a table with 2 columns; a name and timestamp. I want the name to be the first column and the timestamp to be the second column, however, I want the table to be sorted by timestamp in descending order when the table is first shown.
This is how it is currently implemented in
packages/ui/src/components/Table/components/FullDataTable/index.tsx:Proposed solution
Allow for 2 extra optional props on FullDataTable:
Update logic in FullDataTable to use these props and fall back to current functionality if the optional props are not provided