Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ability to specify default sort column on a Table #1055

Open
adriantadros opened this issue Nov 18, 2024 · 0 comments
Open

Allow ability to specify default sort column on a Table #1055

adriantadros opened this issue Nov 18, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@adriantadros
Copy link

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 },
   }
}
@adriantadros adriantadros added the enhancement New feature or request label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant