sorting currency with NA
sorting currency with NA
patchlab
Posts: 6Questions: 1Answers: 0
Hi, I am able to sort the currency column using the html-num-fmt type. but if there is a row that has the NA value in that column, the sorting will not work correctly, it just sort by text instead of number. How can I do something to ignore that NA row from sorting?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
This is correct - you'd need to modify the plug-in to detect the
NA
text and set that to be 0 or -Infinity in the sort order.Allan
can you show me how to modify the plug-in? this is the code I have so far
Hi @patchlab ,
You may be able to use
columns.render
to change the value being passed to the sort routine from NA to an empty string, something likeIt might be worth a try
Cheers,
Colin
@colin I tried it and add console.log there, but doesn't seem it is running that function.
@allan do you mean the below code to modify the plugin?how do I know this code is running? the console.log doesn't seem to be working here.
Yes. If that code isn't running, can you link to a page showing the issue please? Are you using server-side processing?
Allan
@allan
I put the code here now, https://jsfiddle.net/vf6Ljt0k/3/ can you see how I can edit, if you remove the NA TR row, then it sort ok, but with that it is not.
@allan here is the correct link https://jsfiddle.net/vf6Ljt0k/3/
Try this: https://jsfiddle.net/vf6Ljt0k/14/
There are a few problems with your example - the column definations were being given as a string and you weren't stripping the HTML from the cell data or taking account of the comma decimal. I've stripped it right back to the basics there to show how it can work.
Allan
got it, thanks you