Select specific table from multiple DataTables

Select specific table from multiple DataTables

forsakendollforsakendoll Posts: 11Questions: 0Answers: 0
edited April 2014 in Bug reports
I have initialized datatables like this:

[code]
/* Data Table Initialization */
var $materialDataTable = $('.materialTable').dataTable({
"aoColumnDefs": [{ "sClass": "text-center", "aTargets": [ 0,9 ] },
{ 'bSortable': false, 'aTargets': [ 9 ] }]
});
[/code]

I want to add a row to a specific table from the multiple tables that is initialized through that class

I tried this code:

[code]
$materialDataTable[0].fnAddData( [
'1',
'N/A',
'N/A',
'N/A',
'N/A',
'0',
'0',
'0',
'0',
'' ]);
[/code]

But this doesn't work it gives an error [code]Object # has no method 'fnAddData'[/code]

To make it short I want to add a row to a specific table when a button is clicked but I don't know how can I select a specific table from the initialization above.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    But `$materialDataTable[0]` doesn't give you a DataTables object to work with. It gives you the HTML node (this is part of jQuery not DataTables). Hence the error.

    If you want an instance for a single table you could use `$( $materialDataTable[0] ).dataTable().fnAddData()` .

    Or in 1.10 you can use the new table selector methods: http://next.datatables.net/reference/api/#Tables

    Allan
  • forsakendollforsakendoll Posts: 11Questions: 0Answers: 0
    Thanks for introducing me the new selectors I'll be migrating now.
This discussion has been closed.