I have a table with a field "name" which is of text type. It follows a fixed pattern and all the entries are very similar. The entries contain text and numerical values, e.g. Practice 1, Practice 2, Practice 3, ..., Practice n where n can be any number. I need to sort it in the ascending order of the numerical suffix. If I sort it as text only I get something like Practice 1, Practice 10, Practice 2, ..., Practice 9 assuming there are only 10 Practices. However, it has to be sorted as Practice 1, ..., Practice 9, Practice 10 as per my requirement. How can I achieve this?I have attached a picture of my code in the query editor below. I tried casting name to integer using the tointeger() function like below but it gave me an error saying we can't cast on a field.
sort: { a!sortInfo( field: tointeger(record.name), ascending: true ) }
Discussion posts and replies are publicly visible
AFAIK You can't do it while fetching it from backend . Sortinfo takes record field reference, You can't cast a Key (Record field is key), Sort it after fetching data,. One more thing why it's coming in different order ??
if you are sure that they are always going to be Practice n, then you can create a custom field on the record using stripwith(record.name,"Practice ") and then cast the new value as integer. That should help you sort it using that field
You can create a View for that table and declare an integer column where you grab the integer value following the name. Then this column will allow regular DB-side sorting upon querying.