How do I reference an existing datatable?

How do I reference an existing datatable?

totallyplandomtotallyplandom Posts: 27Questions: 1Answers: 1
edited November 2011 in General
Hi All,

I need to be able to reference information from an existing datatable in one of my "static" javascript methods. Meaning, I can't place the method inside the initial jQuery $(). And, if I attempt to make another "datatable()" call, it simply tries to redraw it (which, of course, is bad)

That said, is there a universal (or just generally acceptable) mechanism by which to reference an existing datatable?

FYI, my ultimate goal is to be able to remove checked rows after an independent ajax "delete" call to the back end.

Best.

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    I think newer versions of DataTables don't redraw the table if it exists:
    [code]
    $('#example').dataTable();
    [/code]

    if your version does, you can include bRetrieve : true to simply retrieve the table without processing the initalization (if the table exists it won't reinitialize.. if it doesn't, it will process the init for you)
    [code]
    $('#example').dataTable({
    "bRetrieve": true
    });
    [/code]

    You could also go the route of having a global variable oTable declared outside the jQuery call
    [code]
    var oTable;

    $(document).ready( {
    oTable = $('#example').dataTable({
    // initializers here
    });
    } );
    [/code]
  • totallyplandomtotallyplandom Posts: 27Questions: 1Answers: 1
    How do I reference existing tables if I create multiple in a single instance, like so:

    [code]
    $('#first_table #second_table #third_table').dataTable();
    [/code]
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Two options:

    [code]
    $('#first_table').dataTable();
    $('#second_table').dataTable();
    [/code]

    etc - or you can use iApiIndex: http://datatables.net/development/ (there isn't a huge amount of documentation for it, but you just change it to the index of the table you want in the object).

    Allan
  • totallyplandomtotallyplandom Posts: 27Questions: 1Answers: 1
    Yes, it is fixed in newer versions and yes you must reference them individually. Thanks All!
This discussion has been closed.