Bug in sorting (with fix)
Bug in sorting (with fix)
systematical
Posts: 23Questions: 0Answers: 0
I've found a bug with DataTables 1.10.0-beta.3.dev the following datatables setup:
[code]
var oTable = $('#report-table').dataTable({
"processing": true,
"paging": true,
"ordering": true,
"serverSide": true,
"sAjaxSource": "/hidden/hidden.json",
"ajax": "/hidden/hidden.json",
"sDom": 'frtip',
"iDisplayLength": 300,
"bAutoWidth": false,
"aoColumns": [
{mData:"Data.barcode"},
{mData:"Data.ref"},
{mData:"Data.line_number"},
{mData:"Data.company_name"},
{mData:"Data.name"},
{mData:"Data.buy_price"},
{mData:"Data.status"},
{mData:"Data.total_repairs",bSortable:false},
{mData:"Data.created"}
]
});
[/code]
What occurs is that when a column is sorted that has null as a value the following error is encountered:
[code]
Uncaught TypeError: Cannot read property 'replace' of null jquery.dataTables-1.10.0-beta.3.js?_44617362=:13760
[/code]
Example of XHR JSON response:
[code]
{
"sEcho": 1,
"iTotalRecords": 15517,
"iTotalDisplayRecords": 1039,
"aaData": [
{
"Data": {
"id": "229",
"barcode": "6153850",
"line_number": "3",
"ref": "3091200"
"created": "2013-09-25 14:57:12"
"company_name": "HIDDEN" ,
"barcode": "6153850",
"buy_price": "65.00",
"sell_price": "105.00",
"unit_number": "",
"customer_tag": "",
"production_week": "311",
"status": null,
"total_repairs": null
}
}
]
}
[/code]
Here is the change I made to the code:
[code]
"html-pre": function ( a ) {
return a.replace ?
a.replace( /<.*?>/g, "" ).toLowerCase() :
a+'';
},
[/code]
Changed to:
[code]
"html-pre": function ( a ) {
if(a != null){
return a.replace ?
a.replace( /<.*?>/g, "" ).toLowerCase() :
a+''
}
else{
return a;
}
},
[/code]
[code]
var oTable = $('#report-table').dataTable({
"processing": true,
"paging": true,
"ordering": true,
"serverSide": true,
"sAjaxSource": "/hidden/hidden.json",
"ajax": "/hidden/hidden.json",
"sDom": 'frtip',
"iDisplayLength": 300,
"bAutoWidth": false,
"aoColumns": [
{mData:"Data.barcode"},
{mData:"Data.ref"},
{mData:"Data.line_number"},
{mData:"Data.company_name"},
{mData:"Data.name"},
{mData:"Data.buy_price"},
{mData:"Data.status"},
{mData:"Data.total_repairs",bSortable:false},
{mData:"Data.created"}
]
});
[/code]
What occurs is that when a column is sorted that has null as a value the following error is encountered:
[code]
Uncaught TypeError: Cannot read property 'replace' of null jquery.dataTables-1.10.0-beta.3.js?_44617362=:13760
[/code]
Example of XHR JSON response:
[code]
{
"sEcho": 1,
"iTotalRecords": 15517,
"iTotalDisplayRecords": 1039,
"aaData": [
{
"Data": {
"id": "229",
"barcode": "6153850",
"line_number": "3",
"ref": "3091200"
"created": "2013-09-25 14:57:12"
"company_name": "HIDDEN" ,
"barcode": "6153850",
"buy_price": "65.00",
"sell_price": "105.00",
"unit_number": "",
"customer_tag": "",
"production_week": "311",
"status": null,
"total_repairs": null
}
}
]
}
[/code]
Here is the change I made to the code:
[code]
"html-pre": function ( a ) {
return a.replace ?
a.replace( /<.*?>/g, "" ).toLowerCase() :
a+'';
},
[/code]
Changed to:
[code]
"html-pre": function ( a ) {
if(a != null){
return a.replace ?
a.replace( /<.*?>/g, "" ).toLowerCase() :
a+''
}
else{
return a;
}
},
[/code]
This discussion has been closed.
Replies
Having said that, the html sorting type probably should cope with null values - I'll look into that.
Allan
I made the change to DataTables earlier on today: https://github.com/DataTables/DataTablesSrc/commit/46d1f3bbf . Forgot to post back here.
However, I would still recommend using sDefaultContent.
Allan