$('.dataTable').dataTable(); and API Functions

$('.dataTable').dataTable(); and API Functions

amurdockamurdock Posts: 10Questions: 0Answers: 0
edited October 2011 in DataTables 1.8
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]

Replies

  • OmnimikeOmnimike Posts: 22Questions: 0Answers: 0
    edited October 2011
    Have you tried something like this:

    [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]
  • amurdockamurdock Posts: 10Questions: 0Answers: 0
    I must be doing something wrong because I can't get $(this) to work.

    [code]
    $(this).fnGetPosition( t )
    or
    //just an example
    $(this).AnyAPIFunction(...)
    [/code]

    will always return an error for me.
  • OmnimikeOmnimike Posts: 22Questions: 0Answers: 0
    Sorry, that's my fault. I didn't test what I sent you. Try this instead:
    [code]
    $('.datatable').each(function() {
    var table_position = $(this).dataTable().fnGetPosition(t);
    });
    [/code]
This discussion has been closed.