I am using IDataUtil.sortIDataArrayByKey to sort a document list. The sort works fine except where the key to be sorted on contains entries that start with capitals and small letters, see example below:
Customer name sorted list:
This example can actually happen as some of our customer companies have names that start with small letters.
Any advice on how I can get the list to sort totally alphabetically.
I should also add at this point that the service is generic, so I have no idea of the structure of the array being sorted or the key that will be used.
Thanks for taking the time to read this.
The sorting is done on the ascii value, and the ascii value of a small case letter= ascii value of caps letter+32. This is the reason why the items with small case value are at the bottom of the list, but I guess you already knew this. So with this knowledge, one of the ways could be to convert the values of key you want to sort on to upper (or lower) case. So if you wanna sort the document list on ‘Customer Name’, first loop through the document list and convert the ‘Customer Name’ to upper (or lower) case, then invoke the sortIDataArrayByKey on the document list to sort by the cutomer name.
The ideal case would be to be able to call something like an ‘initcap()’, that converts the first char in a word to caps, but if your scenario allows converting all customer names to upper or lower case, then doing that would be the easiest way.