In workshop I have a filter list that has strings like “Feb 2024, April 2024, March 2024 …” is there a way to sort them by a key and not do a string sort?
I don’t see a way of doing this today in Workshop (though I believe you can in Slate).
If your users would find it acceptable, perhaps you could consider a variation on ISO8601 format, which results in dates/timestamps being sorted in order even if they are stored as strings. For example, instead of February 2024
perhaps you could get away with 2024-02
, 2024-02 Feb
, or even 2402 Feb
.
Another option I might consider is separating out the year and month, so each month could be rendered as 02 - Feb
for clarity. Then, in order to streamline the workflow, I might select the current year by default in my filter list. This would, of course, imply having additional properties on the object type.
Thanks for responding! Yeah both are viable options for sure - I was wondering if I was missing an easy way to do this than having a different property
You could do this with a TS function or with the new (beta) Python functions, pass your array and return the correctly sorted array as a new variable.
@WesField very interesting. Would you mind clarifying how to do that with the filter list widget? I can only figure out how to get it to accept the properties of an object type or linked object type. Is there a way of using Funciont-backed properties for this? Screenshot of what I see (notional data):
Ah I didn’t understand it was exclusively in the Filter widget.
You could use the Object list widget which supports Function-backed properties to render the derived property by returning a FunctionMap<> in the TS function.
Alternatively, you could write a TS function that returns the ObjectSet as correctly sorted up-front or trigger the sort by some button that fires that function.
But agree the best solution for Filter list widget is to make a new Object property that sorts correctly like you suggested.
Also I realized in this case using a string concat with strings as “2024-01”, “2024-02” does not work because then the ordering becomes 2024-12 after 2024-2
@nchakrabarty that is unexpected for sure. You will need the leading zero on the month. Are you sure that’s how things are set up? If I repro this on our stack, the sort order works as expected provided I have a leading zero.
Ah I was missing the leading 0 - many thanks!