custom sorting: Uncaught TypeError: Cannot read property 'oSort' of undefined
custom sorting: Uncaught TypeError: Cannot read property 'oSort' of undefined
I've added custom sorting to a table that has a list of items, prices, hyperlinks and percentages. It's actually working fine but I'm getting a js error on page load: Uncaught TypeError: Cannot read property 'oSort' of undefined.
Here's my script tags:
[code]
[/code]
And my init code (coffee):
[code]
table_name = '#the_table'
$(table_name).dataTable(
"aoColumns": [
{ "sType": "string" },
{ "sType": "formatted-num" },
{ "sType": "percent" },
{ "sType": "formatted-num" },
{ "sType": "html" },
],
"bAutoWidth": true,
"aaSorting": [[3,'desc']],
"bJQueryUI": true,
"fnDrawCallback": () ->
window.resize_center(50)
)
[/code]
So I'm pretty sure that I'm setting that up right, according to the docs. But in my `dataTables.sorting.js` file, I get an error on the first line of this code:
[code]
jQuery.fn.dataTableExt.oSort['formatted-num-asc'] = function(a,b) {
/* Remove any formatting */
var x = a.match(/\d/) ? a.replace( /[^\d\-\.]/g, "" ) : 0;
var y = b.match(/\d/) ? b.replace( /[^\d\-\.]/g, "" ) : 0;
/* Parse and return */
return parseFloat(x) - parseFloat(y);
};
[/code]
The error is: Uncaught TypeError: Cannot read property 'oSort' of undefined. This is a Rails app, the coffee and js live side by side with no issues.
Suggestions for getting rid of this error? The page is working fine, but I think leaving js errors in your page looks unprofessional.
Here's my script tags:
[code]
[/code]
And my init code (coffee):
[code]
table_name = '#the_table'
$(table_name).dataTable(
"aoColumns": [
{ "sType": "string" },
{ "sType": "formatted-num" },
{ "sType": "percent" },
{ "sType": "formatted-num" },
{ "sType": "html" },
],
"bAutoWidth": true,
"aaSorting": [[3,'desc']],
"bJQueryUI": true,
"fnDrawCallback": () ->
window.resize_center(50)
)
[/code]
So I'm pretty sure that I'm setting that up right, according to the docs. But in my `dataTables.sorting.js` file, I get an error on the first line of this code:
[code]
jQuery.fn.dataTableExt.oSort['formatted-num-asc'] = function(a,b) {
/* Remove any formatting */
var x = a.match(/\d/) ? a.replace( /[^\d\-\.]/g, "" ) : 0;
var y = b.match(/\d/) ? b.replace( /[^\d\-\.]/g, "" ) : 0;
/* Parse and return */
return parseFloat(x) - parseFloat(y);
};
[/code]
The error is: Uncaught TypeError: Cannot read property 'oSort' of undefined. This is a Rails app, the coffee and js live side by side with no issues.
Suggestions for getting rid of this error? The page is working fine, but I think leaving js errors in your page looks unprofessional.
This discussion has been closed.
Replies
if ($.fn.dataTableExt !== undefined) { ..stuff... }
For some reason this script is loading twice even though it's only defined once. Might be an issue with how I have Rails set up.
Allan