Skip to content

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

Description

@adriantadros

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 },
   }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions