Quantcast
Viewing all articles
Browse latest Browse all 82127

sorting is not working if we have data with comma , negative/positive values and two decimal values



the data is when sorted as desc

-2,598.00
-3,493.70
-350.00
-36.00
-435.75
-8,200.00
0.00
0.00
17,444.00
27,200.00
736.75

and the code is that i used is

jQuery.fn.dataTableExt.oSort['numeric-comma-asc']  = function(a,b) {
	var x = (a == "-") ? 0 : a.replace( /,/, "." );
	var y = (b == "-") ? 0 : b.replace( /,/, "." );
	x = parseFloat( x );
	y = parseFloat( y );
	return ((x < y) ? -1 : ((x > y) ?  1 : 0));
   };

   jQuery.fn.dataTableExt.oSort['numeric-comma-desc'] = function(a,b) {
	var x = (a == "-") ? 0 : a.replace( /,/, "." );
	var y = (b == "-") ? 0 : b.replace( /,/, "." );
	x = parseFloat( x );
	y = parseFloat( y );
	return ((x < y) ?  1 : ((x > y) ? -1 : 0));
   };		
			
			
	
/* Table initialisation */
$(document).ready( function() {
  $('#myTable').dataTable( {
  
    "sPaginationType": "full_numbers",
    
    "aoColumns": [
			null,
			null,
			null,
			null,
			null,
			{ "sType": "numeric-comma" },
			null,
			null
		]
  }
  
  
   );
} )


Viewing all articles
Browse latest Browse all 82127

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>