Home
Analytics
Change String Sorting Order
kpelzer29
Is there a way I can change the order string values are displayed? I would like the string to appear in ascending order, but also taking into account the numeric value.<br />
<br />
For example, when I do a sort on the string value returned, the string TEST4.10.2 is displaying before TEST4.6.1. I would prefer to show TEST4.6.1 before TEST4.10.2 (since 6 is less than 10). I tried creating a decimal or float computed column using the substring javascript function to take out the string value and try to sort only on the numeric value.<br />
<br />
<em class='bbc'>var x;<br />
x = parseFloat(row["Test"].substring(4, row["Test"].length));</em><br />
<br />
But the value returned is 4.1 and 4.6, so the order does not change. <br />
<br />
Is there a way I can sort the values numerically when the numbers are not decimal values?
Find more posts tagged with
Comments
mwilliams
You could take the substring of the numerical portion, then split it into a string array on the '.' separators, then sort by those 3 different numbers in separate sort conditions. Kinda a long way about doing it, but it should work and shouldn't be too hard to implement.
kpelzer29
Thank you mwilliams. That is a good idea! <br />
<br />
I do not know how many '.' separators there will be in each string though. Can I create the sort conditions dynamically depending on the number of '.' separators? And would it work if the number of '.' separators varies for some strings? For example, one string could be "TEST1.2.30.4.1.5", another could be "TEST1.7", and another could be "TEST5".<br />
<br />
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="74591" data-time="1299874233" data-date="11 March 2011 - 01:10 PM"><p>
You could take the substring of the numerical portion, then split it into a string array on the '.' separators, then sort by those 3 different numbers in separate sort conditions. Kinda a long way about doing it, but it should work and shouldn't be too hard to implement.<br /></p></blockquote>
mwilliams
I don't know if you can add a sort condition after the beforeFactory event, which is before you have access to the data. If you know the maximum number of separators there could be, you could just set that many sorts and when you're splitting your numerical portion of your string up, if it doesn't have a value for all of the sort conditions, you could just assume 0.