Hello All,
Do we have any OOTB function or plug-in function to achieve series sorting ?
Example :
Input
{1,1.1,1.1.1,4,1.2,3,2,2.1,2.2,10,13,12}
Expected output :
{1,1.1,1.1.1,1.2,2,2.1,2.2,3,4,10,12,13}
Discussion posts and replies are publicly visible
Did you try to use todatasubset()?
We have tried todatasubset but it was not sorting as expected. Thanks
Using the sort in a datasubset IS sorting correctly,. The array is a list of string (not number - 1.1.1 is not a valid numeric value) and sorting as as list of string works correctly, but obviously doesn't meet your requirements. You'll have to implement your own custom sort. I suspect (although haven't done the work) that you'll have to examine each item, determine how many 'dots' the item contains, split out the numbers between the dots and implement a nested sort based upon how many levels of dot an item contains.
Thanks for the response Stewart ! Can you provide any sample example for the custom sort? it would be helpful to implement the logics.
I can't provide sample code as it's likely to be quite time consuming. I can recommend an approach, which would be to extract strings that are logically at the same level e.g. '1.1.1.1' and '3.4.56.8' both have 4 numbers (with 3 "dots"). Once extracted to its own list this will sort correctly.
Assuming that for every level below level 1 each item always has a parent present (e.g. '1.1' will have a parent of '1', '3.4.6' will have a parent of '3.4', and '3.4' will have a parent of '3') then you can partition your sorted lists at each level (e.g. all '1.1.x' items in one sorted list, all '1.2.x' items in a sorted list) you should be able to inject your sorted partition lists in the right position in the result list.
a!localVariables( local!values: {"1", "1.1", "1.1.1", "4", "1.2", "3", "2", "2.1", "2.2", "10", "13", "12" }, local!prepare: a!forEach( items: local!values, expression: a!map( first: text(split(fv!item, ".")[1], "0000"), second: text(index(split(fv!item, "."), 2, null), "0000"), third: text(index(split(fv!item, "."), 3, null), "0000"), index: fv!index ) ), local!sorted: todatasubset( local!prepare, a!pagingInfo( startIndex: 1, batchSize: -1, sort: { a!sortInfo(field: "first", ascending: true), a!sortInfo(field: "second", ascending: true), a!sortInfo(field: "third", ascending: true), } ) ), index(local!values, local!sorted.data.index) )
Gah! I'd completely forgotten that the sort now supports nested sortInfo()...that makes the problem WAYYYYY easier...
Thanks Stefan for the sample. we will take it forward from here.