redraw all tables?

redraw all tables?

mambomonkeymambomonkey Posts: 10Questions: 0Answers: 0
edited October 2010 in General
hey there!

I seem to be having a problem targeting some of the datatables, i have a system which creates datatables dynamically so there are multiple tables on on the page.

each table has an id of '#t0', '#t1', '#t2', '#t3' etc...
and all have the same class 'dtable'

im trying to do something like this

$('.dtable').dataTable().fnDraw()

so that all the datatables with this class will redraw, im also trying to do it with the ajax refresh plugin.

But this doesnt work, has anyone got any ideas how I would go about this?

is there there a 'redraw all' function I can use? ( i hope there is ;) )

thanks for your help in advance ;)

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited October 2010
    The DataTables API functions currently operate on only one table at a time (it can be argued if this is right or wrong - I'm not 100% happy with it on reflection - but it's how it is atm!). So what you need to do is to use the $.fn.dataTableExt.iApiIndex parameter to indicate which table you want to act on from the current selector.

    While not identical to what you are looking for, it's very close, the fnFilterAll ( http://datatables.net/plug-ins/api#fnFilterAll ) plug-in will show you how this can be done (it uses fnFilter rather than fnDraw or anything else).

    If you do create an API function for this, perhaps you can post your code so I can put it up on the plug-ins page for others?

    Allan
  • mambomonkeymambomonkey Posts: 10Questions: 0Answers: 0
    Hi allan thanks for the reply,

    ahh right ok, fair enough!

    I tried what you said looking at the fnfilterAll and tried to implement the $.fn.dataTableExt.iApiIndex parameter, but I couldnt quite get it to work (bit of a jquery rookie).

    I have now changed my code so i dont use the oTable variable but call to a specific table id,

    e.g. -> '$('#t3).dataTable().fnReloadAjax();'

    which works sometimes but is not completely stable, if I go back a table (i have tables on a slide) and try to run the
    .fnReloadAjax() function i get:

    Result of expression 'oSettings' [null] is not an object.

    any ideas?

    is this because of the way I am calling the reload ajax function? not using the oTable?

    thanks for the help :)
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    $('#t3).dataTable().fnReloadAjax(); looks fine in principle - as long as iApiIndex is 0 (since there is only one node being matched). Is that the case, or might iApiIndex be >0? Other than that, I'm afraid it's into a bit of debugging and digging through the code to see where it might be going wrong :-(

    Allan
  • mambomonkeymambomonkey Posts: 10Questions: 0Answers: 0
    hi,

    iApiIndex is always 0, just to double check, I need the iapindex to go up for each table right?

    so..

    $('#t0).dataTable() has iapindex of 0
    $('#t1).dataTable() has iapindex of 1
    $('#t2).dataTable() has iapindex of 2

    and so on

    that way it knows to target say..#t1? (if i set the index to 1?)

    so how do I set the target iapindex?

    $.fn.dataTableExt.iApiIndex = 1 ?

    thanks again for the help, im sure theres away around this :)
This discussion has been closed.