mirror of
https://github.com/DataTables/DataTables.git
synced 2024-12-10 22:24:10 +01:00
Fix: When sorting non-string data as a string (type to type detection) then DataTables 1.9 would automatically convert the non-string data to an empty string so it can be sorted. This can result in unexpected ordering in the table. The fix is to check for a toString() function that is available for the data and if it is there, then use it (great for numeric data, dates etc), otherwise the empty string is used (null, methods without toString). This brings 1.9 back into line with how 1.8 behaved - 8549
This commit is contained in:
parent
273aab7e59
commit
409edd791b
4
media/js/jquery.dataTables.js
vendored
4
media/js/jquery.dataTables.js
vendored
@ -11337,7 +11337,9 @@
|
||||
*/
|
||||
"string-pre": function ( a )
|
||||
{
|
||||
if ( typeof a != 'string' ) { a = ''; }
|
||||
if ( typeof a != 'string' ) {
|
||||
a = (a !== null && a.toString) ? a.toString() : '';
|
||||
}
|
||||
return a.toLowerCase();
|
||||
},
|
||||
|
||||
|
@ -5,7 +5,9 @@ $.extend( DataTable.ext.oSort, {
|
||||
*/
|
||||
"string-pre": function ( a )
|
||||
{
|
||||
if ( typeof a != 'string' ) { a = ''; }
|
||||
if ( typeof a != 'string' ) {
|
||||
a = (a !== null && a.toString) ? a.toString() : '';
|
||||
}
|
||||
return a.toLowerCase();
|
||||
},
|
||||
|
||||
|
@ -0,0 +1,47 @@
|
||||
// DATA_TEMPLATE: empty_table
|
||||
oTest.fnStart( "8549 - string sorting non-string types" );
|
||||
|
||||
$(document).ready( function () {
|
||||
var test = false;
|
||||
|
||||
$.fn.dataTable.ext.sErrMode = "throw";
|
||||
|
||||
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Shallow properties
|
||||
*/
|
||||
|
||||
$('#example').dataTable( {
|
||||
"aaData": [
|
||||
[ null ],
|
||||
[ 5 ],
|
||||
[ "1a" ],
|
||||
[ new Date(0) ]
|
||||
],
|
||||
"aoColumns": [
|
||||
{ "sTitle": "Test" }
|
||||
]
|
||||
} );
|
||||
|
||||
oTest.fnTest(
|
||||
"Sorting works - first cell is empty",
|
||||
null,
|
||||
function () { return $('#example tbody tr:eq(0) td:eq(0)').html() === ""; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Second cell is 1a",
|
||||
null,
|
||||
function () { return $('#example tbody tr:eq(1) td:eq(0)').html() === "1a"; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Third cell is 5",
|
||||
null,
|
||||
function () { return $('#example tbody tr:eq(2) td:eq(0)').html() === "5"; }
|
||||
);
|
||||
|
||||
|
||||
oTest.fnComplete();
|
||||
} );
|
Loading…
Reference in New Issue
Block a user