Sorting data by number while ignoring leading alpha
Sorting data by number while ignoring leading alpha
Hi, I'm working on some code that is supposed to list document numbers in descending order. However, some documents have a letter at the beginning of the number and some don't. The result is that the document numbers are split between the ones with the letter, sorted in descending order, and the ones without the letter coming after, sorted in descending order. For example:
a85065
a85053
a85041
85063
85052
What I want to do is sort the documents by numerical order while ignoring the letter. For example:
a85065
85063
a85053
85052
a85041
The problem is I still need the letter to display on the document number, so it is not as easy as popping off the letter. Does anyone have any ideas?
Here is the code for the sort as-is:
j$("table[id$=documentsReceivedBlock]").DataTable({
"order": [[0, 'desc']],
"bFilter": false,
"bPaginate": false,
"bInfo": false,
"columnDefs: [
{ "type": "date-sort", "targets": [1,2,5] }
]
});
Thanks!
Answers
Hi @dtarvin ,
The
columns.render
can return different representations of the same data depending upon it's purpose, i.e. displaying, sorting, filtering, etc. If you use that, as in this example here, it'll do what you want,Cheers,
Colin
Thanks, but I just can't seem to get it to work.
My code is pretty much exactly what you want. If it's not working on your table, why don't you repost what you currently have so we can take a look.
Oh, and I also tried it with the "order" commented out.
I'm assuming that column 0 is the column with these document numbers in? You don't need data on line 21, I'd remove that - it's only needed if you're using object based data, and then the
columns.data
should be declared in thecolumns
object.I've had good luck with the Natural Sorting plugin for this type of data.
Kevin
Hi David,
I see you posted this on StackOverflow yesterday. Is this still an issue?
Cheers,
Colin
Sorry for the delayed response. I ended up using a regex. Thanks!