Scientific notation sorting
Sort data which is written in exponential notation.
- Author: Nick Schurch
This plug-in will treat numbers which are in scientific notation (for
example 1E-10
, 1.2E6
etc) and sort them numerically.
Plug-in code
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"scientific-pre": function ( a ) {
return parseFloat(a);
},
"scientific-asc": function ( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"scientific-desc": function ( a, b ) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );
CDN
This plug-in is available on the DataTables CDN:
Note that if you are using multiple plug-ins, it is beneficial in terms of performance to combine the plug-ins into a single file and host it on your own server, rather than making multiple requests to the DataTables CDN.
Version control
If you have any ideas for how this plug-in can be improved, or spot anything that is in error, it is available on GitHub and pull requests are very welcome!
- This plug-in: scientific.js
- Full DataTables plug-ins repository: DataTables/Plugins
Example
$('#example').dataTable( {
columnDefs: [
{ type: 'scientific', targets: 0 }
]
} );