Select specific table from multiple DataTables
Select specific table from multiple DataTables
forsakendoll
Posts: 11Questions: 0Answers: 0
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.
[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.
This discussion has been closed.
Replies
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