-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
switch beetween ASC, DESC, NO filter #73
Comments
That sounds useful. I'm thinking this part const updateSortOrder = colKey => {
if (colKey === sortBy) {
sortOrder = sortOrder === 1 ? -1 : 1;
} else {
sortOrder = 1;
}
}; the one thing I'm not sure on is whether a setting of |
Your idea of a sortOrders prop is great ! That would also allow anyone to order ASC or DESC first. I would go with something like this: export let sortOrders = [1, -1]
const updateSortOrder = colKey => {
if (colKey === sortBy) {
sortOrder = sortOrders[(sortOrders.findIndex(o => o === sortOrder) + 1) % sortOrders.length];
} else {
sortOrder = 1;
// we could even have somting like: sortOrders[0];
}
}; Also, I prefer having a method that returns a value (setOrder) to have tests ;) Jest teststest('updateSortOrder', () => {
// const updateSortOrder = (colKey, sortBy, sortOrder, sortOrders)
expect(updateSortOrder('name', 'year', undefined, [1, -1])).toStrictEqual(1);
expect(updateSortOrder('name', 'year', undefined, [1, -1, 0])).toStrictEqual(1);
expect(updateSortOrder('name', 'name', undefined, [1, -1])).toStrictEqual(1);
expect(updateSortOrder('name', 'name', 1, [1, -1])).toStrictEqual(-1);
expect(updateSortOrder('name', 'name', -1, [1, -1])).toStrictEqual(1);
expect(updateSortOrder('name', 'name', undefined, [1, -1, 0])).toStrictEqual(1);
expect(updateSortOrder('name', 'name', 1, [1, -1, 0])).toStrictEqual(-1);
expect(updateSortOrder('name', 'name', -1, [1, -1, 0])).toStrictEqual(0);
expect(updateSortOrder('name', 'name', 0, [1, -1, 0])).toStrictEqual(1);
}) |
agreed, a functional approach is better. And having |
I came up with a question: I know that it would be a breaking changes, but, does it make sense to have ASC/DESC by default without the opportunity to unset a filter? |
Unless there's a compelling reason I would keep default as ASC/DESC without ability to unset. a PR is welcome, thanks |
Thanks |
Hello,
It's me again.
When clicking on a column, if the column is sortable, it is sorted ASC, then DESC and there is no way to remove the sorting criteria. I would maybe suggest to have a prop to either switching from ASC to DESC or from ASC to DESC to NO filter. Also, usually, when a column if sortable, there is a two-arrow icon indicating that the column is sortable.
I haven't tried but it is theoretically possible to override this behavior with the exposed clickCol event and sortorder / sortby props.
If you find this relevant, I can submit a PR.
The text was updated successfully, but these errors were encountered: