$('.dataTable').dataTable(); and API Functions
$('.dataTable').dataTable(); and API Functions
amurdock
Posts: 10Questions: 0Answers: 0
My page has 4 tables on it each with the datatable class like shown below.
[code]$('.datatable').dataTable();[/code]
I am trying to use several API functions on the tables(fnGetPosition and fnUpdate) but they will only work for the first table on the page.
Here is a quick example:
[code]var table_position = oTable.fnGetPosition( t );[/code]
On the first table on the page everything works, but all other return NULL.
The var 't' is the table row that I am selecting as shown"
[code]
138
14383.DWG
6W2VSD42
[/code]
[code]$('.datatable').dataTable();[/code]
I am trying to use several API functions on the tables(fnGetPosition and fnUpdate) but they will only work for the first table on the page.
Here is a quick example:
[code]var table_position = oTable.fnGetPosition( t );[/code]
On the first table on the page everything works, but all other return NULL.
The var 't' is the table row that I am selecting as shown"
[code]
138
14383.DWG
6W2VSD42
[/code]
This discussion has been closed.
Replies
[code]
$('.datatable').each(function() {
var table_position = $(this).fnGetPosition(t);
});
[/code]
I suspect that the datatables api function assume you are working with a jquery object containing a single element, so in your case you will probably have to explicitly loop over each of the tables in the jquery object.
This might not be the case in your actual code, but in the example if you try to look for the position of a single tr node in multiple tables it could only possibly be found in one of the tables, so this might also get you where you want to go (assuming you don't have duplicate ids on your page):
[code]
var $tr = $('#tank_tr_4419');
var table_position = $tr.closest('.datatable').fnGetPosition($tr[0]);
[/code]
[code]
$(this).fnGetPosition( t )
or
//just an example
$(this).AnyAPIFunction(...)
[/code]
will always return an error for me.
[code]
$('.datatable').each(function() {
var table_position = $(this).dataTable().fnGetPosition(t);
});
[/code]