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

SPIKE: Add custom sorting function to table columns #2505

Open
cjwinsor opened this issue May 3, 2024 · 3 comments
Open

SPIKE: Add custom sorting function to table columns #2505

cjwinsor opened this issue May 3, 2024 · 3 comments
Assignees
Labels
5 5 story points external-request Bugs and features reported by individuals from other teams in Trimble

Comments

@cjwinsor
Copy link
Contributor

cjwinsor commented May 3, 2024

References: #1602
https://tanstack.com/table/latest/docs/guide/sorting

Define what the function needs to be that is passed to sortingFn such that the end user can define their own custom sorting functions. Ideally they would pass a function like (a, b) = > { // implementation }.

Document the shape of the expected function and if we need or want to simplify it.

@github-actions github-actions bot added the external-request Bugs and features reported by individuals from other teams in Trimble label May 3, 2024
@cjwinsor cjwinsor added the 5 5 story points label May 9, 2024
@prashanthr6383 prashanthr6383 self-assigned this May 15, 2024
@prashanthr6383
Copy link
Collaborator

prashanthr6383 commented May 23, 2024

@cjwinsor This is an example of custom sorting function the users can use prop sortingFn : sortStatusFn and define

const sortStatusFn: SortingFn<Person> = (rowA, rowB, _columnId) => {
  const statusA = rowA.original.status
  const statusB = rowB.original.status
  const statusOrder = ['single', 'complicated', 'relationship']
  return statusOrder.indexOf(statusA) - statusOrder.indexOf(statusB)
}

Date Sorting 

const dateSortingFn= (rowA, rowB, _columnId) => {
  const dateA = new Date(rowA.original.createdAt);
  const dateB = new Date(rowB.original.createdAt);
  return dateA.getTime() - dateB.getTime();
}

@cjwinsor
Copy link
Contributor Author

Based on this, we are good to create a story to add examples into the storybook.

@prashanthr6383
Copy link
Collaborator

prashanthr6383 commented May 27, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 5 story points external-request Bugs and features reported by individuals from other teams in Trimble
Projects
Status: Done
Development

No branches or pull requests

2 participants