Replies: 1 comment 1 reply
-
Hi Grayson, I had the same issue when I was implementing a custom widget for sorting and filtering rows. The way I solved this was by setting useTable(
{
columns,
data,
disableSortRemove: true,
filterTypes,
},
useFilters,
useSortBy,
useColumnOrder,
useFlexLayout,
useResizeColumns,
useRowSelect) If you set https://react-table.tanstack.com/docs/api/useSortBy Inside the custom widget you may use this to sort ascending and descending: const sortAscHandler = (column, event) => {
const toggleProps = column.getSortByToggleProps();
// the first condition checks if your column is unsorted and this happens only the first time because your column is always sorted once one of these handlers is fired
if (column.sortedIndex === -1 || column.isSortedDesc) {
toggleProps.onClick(event);
}
};
const sortDescHandler = (column, event) => {
const toggleProps = column.getSortByToggleProps();
if (column.sortedIndex === -1 || !column.isSortedDesc) {
toggleProps.onClick(event);
}
}; |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm trying to create a custom widget for column sorting similar to the below image.

The challenge I'm having is when calling column.toggleSortBy(), the state repeatedly changes from descending -> ascending -> none. There doesn't seem to be a way to set the sortBy to either ascending or descending, such as column.setSortAsc(true). Is there a known workaround to setting the sortBy for a column directly, without having to toggle in order to get there?
I also tried setSortBy([{columnId: column.id, desc: false}]) which works as expected, but setSortBy([{columnId: column.id, desc: true}]) has no effect.
Thanks,
Grayson
Beta Was this translation helpful? Give feedback.
All reactions