/** * When dealing with computer file sizes, it is common to append a post fix * such as B, KB, MB or GB to a string in order to easily denote the order of * magnitude of the file size. This plug-in allows sorting to take these * indicates of size into account. * * A counterpart type detection plug-in is also available. * * @name File size * @summary Sort abbreviated file sizes correctly (8MB, 4KB, etc) * @author Allan Jardine - datatables.net * * @example * $('#example').DataTable( { * columnDefs: [ * { type: 'file-size', targets: 0 } * ] * } ); */ jQuery.fn.dataTable.ext.type.order['file-size-pre'] = function ( data ) { var matches = data.match( /^(\d+(?:\.\d+)?)\s*([a-z]+)/i ); var multipliers = { b: 1, kb: 1000, mb: 1000000, gb: 1000000000, tb: 1000000000000, pb: 1000000000000000 }; if (matches) { var multiplier = multipliers[matches[2].toLowerCase()]; return parseFloat( matches[1] ) * multiplier; } else { return -1; }; };