Closed joeleaver closed 9 months ago
heya @joeleaver, I think it's a good suggestion! There are 3 ways to do it that I propose:
sortValueObj
to not only be able to return number
, but also string
, so string | number
, orsortValueObj
, have some kind of key called __global
that will apply the modifier to all columns (so we don't have to do (1) for all keys), orsortValueObj
not only able to receive a Record<string, Function>
but make it also Record<string, Function> | SortValueFunction
. This SortValueFunction
is something like (key: name) => string | number
. So, we can do something like:sortValueObj: (key, value) => {
if (key === 'date') return parse(`${value}`, 'MMMM dd, yyyy', new Date()).getTime()
return value.toLowerCase()
}
What do you think? I'm thinking maybe option 3 is better but the name sortValueObj
would be a bit misleading since it can also accept a function. If we go with 3, maybe I'd consider creating another field with exact same type, but the name is sortValueGetter
or sortValueProcessor
(and deprecate sortValueObj
so we can remove it on the next major version).
Or maybe we can just simply check if the column value type is a string, then make it toLowerCase()
there so no external process is required.
EDIT: nevermind, I think this is not a good idea since it's a breaking change, probably the 3rd option above is the most ideal
hi @joeleaver, could you try v3.13.1 and see how it goes with your use case? https://codesandbox.io/p/sandbox/distracted-thunder-nx87tq?file=%2Fsrc%2FApp.tsx%3A77%2C40
sortProps={{
columnValueProcessor: (key, row) => {
const value = row[key];
if (key === "name") {
return value.toLowerCase();
}
return value;
},
}}
This seems to work just fine, thanks for implementing it!
Cool, thanks for the confirmation! I'll close this issue, then. Let me know if you need further help.
The sorting behavior for strings is case sensitive. I'd like to be able to sort by string.toLocaleLowercase.
sortValueObj requires a number as its return type, so there isn't a convenient way to do this, unless I'm missing something obvious.