This seemed to work fine (when using <10 resources), however, today I found out that when using more than 10 resources, for example 14 (numbered from 1 to 14), it sorts in the following way:
1
10
11
12
13
14
2
3
4
etc.
It seems to sort the number "alphabetically"
How can I tell scheduler to treat the "resourceOrder" field as an integer/number when sorting on it?
NotE: I realise I can divert to numbering like this: 001, 002, 003, or A, B, C etc. but this is not an ideal solution, because the resourceOrder is numeric in other parts of my (server-sided) code.
Thanks for the help!
Laurens
Re: [INFO REQ] Sort by custom field based on numeric value (in stead of alphabetically)
sorters : [{ field: 'resourceOrder', fn: (valueA, valueB) => { // do comparison here }}]
Re: [INFO REQ] Sort by custom field based on numeric value (in stead of alphabetically)
Posted: Tue Nov 14, 2023 4:33 pm
by lxxrxns
Hi marcio, thanks for the quick response.
Which values would I have to compare? I'm assuming you mean some kind of function that compares different rows with eachother and returns a number based on their relative values for "resourceOrder", but I wouldn't know how to write this exactly...
Thanks for the help!
Re: [INFO REQ] Sort by custom field based on numeric value (in stead of alphabetically)
Re: [INFO REQ] Sort by custom field based on numeric value (in stead of alphabetically)
Posted: Tue Nov 14, 2023 5:28 pm
by lxxrxns
Hi marcio,
That seems to work for when resourceOrders are set indeed, but it also creates an order when resourceOrders are in fact empty in my database (which is when I want to sort by 'name'):
Is there a way to make your fn : (recordA, recordB) => {} function only return a value if resourceOrder is in fact set (not NULL)?
Thanks again for the help!!
Re: [INFO REQ] Sort by custom field based on numeric value (in stead of alphabetically)
Posted: Tue Nov 14, 2023 5:33 pm
by marcio
Hey,
The function works just like a JS sort logic, so, before the return, you should return 0 to maintain the order of the records (in that case, ignore the resourceOrder sort function).