You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Plugins/type-detection/formatted-num.js

60 lines
1.7 KiB
JavaScript

/*! © SpryMedia Ltd - datatables.net/license */
(function( factory ){
if ( typeof define === 'function' && define.amd ) {
// AMD
define( ['datatables.net'], function ( $ ) {
return factory( $, window, document );
} );
}
else if ( typeof exports === 'object' ) {
// CommonJS
module.exports = function (root, $) {
if ( ! root ) {
// CommonJS environments without a window global must pass a
// root. This will give an error otherwise
root = window;
}
if ( ! $.fn.dataTable ) {
require('datatables.net')(root, $);
}
return factory( $, root, root.document );
};
}
else {
// Browser
factory( jQuery, window, document );
}
}(function( $, window, document, undefined ) {
'use strict';
var DataTable = $.fn.dataTable;
/**
* This plug-in will strip out non-numeric formatting characters such that a
* formatted number (for example 1,000,000) can be detected automatically and
* sorted numerically. Note that characters a-z are not automatically removed,
* otherwise there is a risk of detecting columns as numeric which should not
* be.
*
* DataTables 1.10+ has formatted number type detection and sorting abilities
11 years ago
* built-in. As such this plug-in is marked as deprecated, but might be useful
* when working with old versions of DataTables.
*
* @name Formatted numbers
* @summary formatted_numbers
11 years ago
* @deprecated
* @author [Allan Jardine](http://sprymedia.co.uk)
*/
DataTable.ext.type.detect.unshift(function (data) {
var deformatted = data.replace(/[^\d\-\.\/a-zA-Z]/g, '');
var isNumeric = !isNaN(deformatted - parseFloat(deformatted));
return isNumeric || deformatted === '-' ? 'formatted-num' : null;
});
return DataTable;
}));