Plugin not working - giving errors!

Plugin not working - giving errors!

ElliotReeveyElliotReevey Posts: 3Questions: 0Answers: 0
edited February 2013 in Plug-ins
So I am using the Datatables plugin to sort data within my tables.

The data I have stored includes numbers (22.34), currency ($223,400) and formatted numbers (233,623). I have seen the section of the website about sorting plugins (http://datatables.net/plug-ins/sorting).

I have spent the last 2 hours attempting to get the formatted number plugin to work but keep getting errors no matter what I try.

Here is my code:

Included is the following script:

[code][/code]

Which contains the following:
[code]
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"formatted-num-pre": function ( a ) {
a = (a==="-") ? 0 : a.replace( /[^\d\-\.]/g, "" );
return parseFloat( a );
},

"formatted-num-asc": function ( a, b ) {
return a - b;
},

"formatted-num-desc": function ( a, b ) {
return b - a;
}
} );
[/code]
Then the main code:
[code]

$(document).ready(function() {

var oTable = $('#sample_1').dataTable( {
"sDom": "<'row-fluid'<'span4'l><'span4 tbl_time_frame'><'span4'f>r>t<'row-fluid'<'span4'i><'span4'><'span4'p>>",
"sPaginationType": "bootstrap",
"aoColumns": [
{ "sType": "numeric" },
null,
{ "sType": "formatted-num"},
{ "sType": "numeric"},
null,
null,
null,
null,
null
],
"oLanguage": {
"sLengthMenu": "_MENU_ records per page",
"oPaginate": {
"sPrevious": "Prev",
"sNext": "Next"
}
},
"fnInitComplete": jQuery('.tooltips').tooltip()
});
});
[/code]
I have the following error on page load:

[code]Uncaught TypeError: Cannot read property 'oSort' of undefined [/code]
Then when I click on the third row I get the following errors alternately:

[code]Uncaught TypeError: Property 'formatted-num-asc' of object # is not a function jquery.dataTables.js:4038[/code]
[code]Uncaught TypeError: Property 'formatted-num-desc' of object # is not a function [/code]

Can anyone help?

Cheers

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Please link to a test case: http://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read

    Allan
This discussion has been closed.