DataTables/Regex question for sorting

I have a DataTables page setup so I can sort the “Amount” column at the link below. The problem is that there is mixed data (numbers and text) which is causing the sorting to get messed up. I think I need to modify the “formatted-numbers.js” code below so the Regex treats the word “Undisclosed” as 0 so it sorts properly. Does anyone have experience with DataTables or Regex to advise?

Here is the current page:

And here is the ‘formatted numbers’ plugin code im using:

jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"formatted-num-pre": function ( a ) {
a = (a === "-" || a === "") ? 0 : a.replace( /[^\d\-\.]/g, "" );
return parseFloat( a );
},
"formatted-num-asc": function ( a, b ) {
return a - b;
},
"formatted-num-desc": function ( a, b ) {
return b - a;
}
} );

Source to code above:

I’m not familiar with extjs but from what you’re saying you may be able to simply do this

"formatted-num-pre": function ( a ) {
  a = (a === "-" || a === "" || a === 'Undisclosed') ? 0 : a.replace( /[^\d\-\.]/g, "" );
  return parseFloat( a );
},

The ternary operator is doing the same thing as this.

if (a === "-" || a === "" || a === 'Undisclosed') {
  a = 0;
} else {
  // remove all chars except digits, '-' and '.'
  a.replace( /[^\d\-\.]/g, "" );
}
1 Like

Thank you that worked!