| 1 |
/*! © SpryMedia Ltd - datatables.net/license */ |
| 2 |
|
| 3 |
(function( factory ){ |
| 4 |
if ( typeof define === 'function' && define.amd ) { |
| 5 |
// AMD |
| 6 |
define( ['jquery', 'datatables.net'], function ( $ ) { |
| 7 |
return factory( $, window, document ); |
| 8 |
} ); |
| 9 |
} |
| 10 |
else if ( typeof exports === 'object' ) { |
| 11 |
// CommonJS |
| 12 |
var jq = require('jquery'); |
| 13 |
var cjsRequires = function (root, $) { |
| 14 |
if ( ! $.fn.dataTable ) { |
| 15 |
require('datatables.net')(root, $); |
| 16 |
} |
| 17 |
}; |
| 18 |
|
| 19 |
if (typeof window === 'undefined') { |
| 20 |
module.exports = function (root, $) { |
| 21 |
if ( ! root ) { |
| 22 |
// CommonJS environments without a window global must pass a |
| 23 |
// root. This will give an error otherwise |
| 24 |
root = window; |
| 25 |
} |
| 26 |
|
| 27 |
if ( ! $ ) { |
| 28 |
$ = jq( root ); |
| 29 |
} |
| 30 |
|
| 31 |
cjsRequires( root, $ ); |
| 32 |
return factory( $, root, root.document ); |
| 33 |
}; |
| 34 |
} |
| 35 |
else { |
| 36 |
cjsRequires( window, jq ); |
| 37 |
module.exports = factory( jq, window, window.document ); |
| 38 |
} |
| 39 |
} |
| 40 |
else { |
| 41 |
// Browser |
| 42 |
factory( jQuery, window, document ); |
| 43 |
} |
| 44 |
}(function( $, window, document ) { |
| 45 |
'use strict'; |
| 46 |
var DataTable = $.fn.dataTable; |
| 47 |
|
| 48 |
|
| 49 |
/** |
| 50 |
* Data can often be a complicated mix of numbers and letters (file names |
| 51 |
* are a common example) and sorting them in a natural manner is quite a |
| 52 |
* difficult problem. |
| 53 |
* |
| 54 |
* Fortunately the Javascript `localeCompare` method is now widely supported |
| 55 |
* and provides a natural sorting method we can use with DataTables. |
| 56 |
* |
| 57 |
* @name Natural sorting |
| 58 |
* @summary Sort data with a mix of numbers and letters _naturally_. |
| 59 |
* @author Allan Jardine |
| 60 |
* @requires DataTables 2+ |
| 61 |
* |
| 62 |
* @example |
| 63 |
* // Natural sorting |
| 64 |
* new DataTable('#myTable', |
| 65 |
* columnDefs: [ |
| 66 |
* { type: 'natural', target: 0 } |
| 67 |
* ] |
| 68 |
* } ); |
| 69 |
* |
| 70 |
* @example |
| 71 |
* // Html can be stripped from sorting by using 'natural-nohtml' such as |
| 72 |
* new DataTable('#myTable', |
| 73 |
* columnDefs: [ |
| 74 |
* { type: 'natural-nohtml', target: 0 } |
| 75 |
* ] |
| 76 |
* } ); |
| 77 |
* |
| 78 |
* @example |
| 79 |
* // Case insensitive natural sorting |
| 80 |
* new DataTable('#myTable', |
| 81 |
* columnDefs: [ |
| 82 |
* { type: 'natural-ci', target: 0 } |
| 83 |
* ] |
| 84 |
* } ); |
| 85 |
* |
| 86 |
*/ |
| 87 |
DataTable.type("natural", { |
| 88 |
order: { |
| 89 |
asc: function (a, b) { |
| 90 |
return a.localeCompare(b, navigator.languages[0] || navigator.language, { |
| 91 |
numeric: true, |
| 92 |
ignorePunctuation: true, |
| 93 |
}); |
| 94 |
}, |
| 95 |
desc: function (a, b) { |
| 96 |
return (a.localeCompare(b, navigator.languages[0] || navigator.language, { numeric: true, ignorePunctuation: true }) * |
| 97 |
-1); |
| 98 |
}, |
| 99 |
}, |
| 100 |
className: "natural-sort", |
| 101 |
}); |
| 102 |
DataTable.type("natural-nohtml", { |
| 103 |
order: { |
| 104 |
asc: function (a, b) { |
| 105 |
a = DataTable.util.stripHtml(a); |
| 106 |
b = DataTable.util.stripHtml(b); |
| 107 |
return a.localeCompare(b, navigator.languages[0] || navigator.language, { |
| 108 |
numeric: true, |
| 109 |
ignorePunctuation: true, |
| 110 |
}); |
| 111 |
}, |
| 112 |
desc: function (a, b) { |
| 113 |
a = DataTable.util.stripHtml(a); |
| 114 |
b = DataTable.util.stripHtml(b); |
| 115 |
return (a.localeCompare(b, navigator.languages[0] || navigator.language, { numeric: true, ignorePunctuation: true }) * |
| 116 |
-1); |
| 117 |
}, |
| 118 |
}, |
| 119 |
className: "natural-sort", |
| 120 |
}); |
| 121 |
DataTable.type("natural-ci", { |
| 122 |
order: { |
| 123 |
asc: function (a, b) { |
| 124 |
a = a.toString().toLowerCase(); |
| 125 |
b = b.toString().toLowerCase(); |
| 126 |
return a.localeCompare(b, navigator.languages[0] || navigator.language, { |
| 127 |
numeric: true, |
| 128 |
ignorePunctuation: true, |
| 129 |
}); |
| 130 |
}, |
| 131 |
desc: function (a, b) { |
| 132 |
a = a.toString().toLowerCase(); |
| 133 |
b = b.toString().toLowerCase(); |
| 134 |
return (a.localeCompare(b, navigator.languages[0] || navigator.language, { numeric: true, ignorePunctuation: true }) * |
| 135 |
-1); |
| 136 |
}, |
| 137 |
}, |
| 138 |
className: "natural-sort", |
| 139 |
}); |
| 140 |
|
| 141 |
|
| 142 |
return DataTable; |
| 143 |
})); |
| 144 |
|