Multiple tables

Multiple tables

oc666oc666 Posts: 2Questions: 0Answers: 0
edited August 2009 in General
Hello

I have multiple tables on one page. I want to add raw only to the second table. How could I get the object to run fnSort function on this object? How could I use this function dynamically?

I see this: http://datatables.net/examples/basic_init/multiple_tables.html
but it only present the tables without any function (like add raw: http://datatables.net/examples/api/add_row.html).

Thanks for the help.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi oc666,

    If you are using a single call to initialise multiple tables, you can use the property '$.fn.dataTableExt.iApiIndex' to change which table is used by the API functions (see http://datatables.net/development/ ). For example if $('.data').dataTable(); inits 5 tables, and you want to add data to the 3rd, you would do: "$.fn.dataTableExt.iApiIndex=2; oTables.fnAddData(...);".

    Regards,
    Allan
  • oc666oc666 Posts: 2Questions: 0Answers: 0
    edited August 2009
    allan, thanks for your reply.
    Could I call the table object via its id (html id)?

    Thanks
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi oc666,

    You could probably parse through the $.fn.dataTableSettings array of objects to find the settings which correspond to the target table - but I think it's probably much easier if you just use a global variable - or attach it to a global variable.

    Regards,
    Allan
  • pmalvespmalves Posts: 18Questions: 0Answers: 0
    With the risk of cross-posting, I also need this. If I can avoid setting a var and get it from the dom, the better
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi pmalves,

    Probably best to refer to my answer in your other post http://datatables.net/forums/comments.php?DiscussionID=538 . It's possible, but I would very much recommend against it. Is there any reason not to have another variable?

    Allan
  • ElMamberoElMambero Posts: 1Questions: 0Answers: 0
    hi, this is the solution. sTableId this attribute contains the Table ID

    "sAjaxSource": 'accion.asp',
    "fnServerData": function ( sSource, aoData, fnCallback ) {
    var id = $(this).attr('sTableId')
    aoData.push( { "name": "Accion", "value": id } );
    $.getJSON( sSource, aoData, function (json) {
    fnCallback(json)
    } );
    }


    Regards.
This discussion has been closed.