Cannot read property 'asSorting'
Cannot read property 'asSorting'
I use DataTables in several pages of my app. I am trying to initialize another but keep getting
'TypeError: Cannot read property 'asSorting' of undefined'. The table is well-formed with used in thead
and is no different than any other table in the app as far as I can see. What should I look for?
Thanks in advance.
'TypeError: Cannot read property 'asSorting' of undefined'. The table is well-formed with used in thead
and is no different than any other table in the app as far as I can see. What should I look for?
Thanks in advance.
This discussion has been closed.
Replies
Allan
HTML:
[code]
Device Status
...
[/code]
jQuery:
[code]
$('#device_status').children('table').dataTable();
[/code]
(also tried:)
[code]
$('#device_status').children('table').dataTable(
{
'aoColumnDefs':
[
{ 'asSorting': ['asc','desc'], 'aTargets': ['_all'] }
]
});
[/code]
No matter what I do (try through console, try another table), I get the same error:
Uncaught TypeError: Cannot read property 'asSorting' of undefined
Any help? I'm frustrated that I've run into a brick wall right at the start of my time using DataTables. I'm going to try again with Firefox, but I want my site to work both with Firefox and Chrome..
Many thanks,
Aaron
I've just put together an example with your code, and it seems to work okay in Chrome for me: http://live.datatables.net/asiyow/edit#javascript,html (click the render button to see the resulting table).
If you could link me to an example page which shows the error, that would be great.
Allan
We've narrowed down the problem to the fact that our tables are dynamically generated through jQuery. We've appended to your code an example of a dynamically-generated table not working:
http://live.datatables.net/asiyow/2/edit#javascript,html,live
We're dynamically generating all of our tables using jQuery (using data pulled asynchronously from our server), so any help with applying dataTables to these would be greatly appreciated!
Thanks,
Aaron
Going through the code on that site, I realized that I'd forgotten to add 's to my tag. When I added the as well, the code started working!
http://live.datatables.net/asiyow/4/edit
But I'm still having some problems with the tables in my app, and I think it's because I'm loading the data in after dataTable() is called. I'm going to take a look at the dataTables documentation to find out the preferred way to add rows dynamically to a dataTable.
Thanks for your help, and let me know if you have any further insight into my problem!
-Aaron
http://live.datatables.net/asiyow/5/edit
As you can see, we're adding data dynamically to the dataTable, and dataTables is apparently looking at the table data at the time it's called. Since I know that dataTables supports dynamically adding data, I'm now looking into the preferred ways to do so.
Once again, thanks for your help, especially for pointing us to jsbin, which is a really cool site :)
[code]
$('#my_jquery_table').dataTable();
$('#my_jquery_table tbody')
.append('Red12')
.append('Green100')
} );
[/code]
To add data to the table you need to use fnAddData ( http://datatables.net/api#fnAddData ). DataTables doesn't listen to the DOM, so it doesn't know when you've added a new row - so you need to use the API to modify the table if you want the changes to be registered with DataTables.
Allan
Yep, we're now using fnAddData; just have to start using the DataTables API for all six of our tables, for all the different ways we plan to add, modify, and remove table data. I'm looking forward to it ^^ If I have any questions unrelated to this topic, I'll post a new topic on this forum.
Thanks,
Aaron
Hope you enjoy using DataTables!
Allan