diff --git a/media/js/jquery.dataTables.js b/media/js/jquery.dataTables.js index 3795f1b5..9c64c8b3 100644 --- a/media/js/jquery.dataTables.js +++ b/media/js/jquery.dataTables.js @@ -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(); }, diff --git a/media/src/ext/ext.sorting.js b/media/src/ext/ext.sorting.js index 44382579..93ab015b 100644 --- a/media/src/ext/ext.sorting.js +++ b/media/src/ext/ext.sorting.js @@ -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(); }, diff --git a/media/unit_testing/tests_onhold/2_js/8549--string-sorting-nonstrings.js b/media/unit_testing/tests_onhold/2_js/8549--string-sorting-nonstrings.js new file mode 100644 index 00000000..57ffebc0 --- /dev/null +++ b/media/unit_testing/tests_onhold/2_js/8549--string-sorting-nonstrings.js @@ -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(); +} ); \ No newline at end of file