How to get data array by clicking on a TR?

How to get data array by clicking on a TR?

KyvuKyvu Posts: 11Questions: 0Answers: 0
edited May 2012 in General
Hello everyone,

I have many and many independant datatables placed on my HTML page (on a jQuery tabs) and I would like to get the data array of a TR when clicking on every row of every table.

After init, all tables have an ID in this form: mydatatablegroupea1, mydatatablegroupea2, mydatatablegroupea3, mydatatablegroupea4 and so on...

Now, how is the best way to get by click all the values of a particular TR of a particular datatable?

I tried by myself with for example fnGetData(this) but it does not work. :-(

[code]

$("table[id*=mydatatablegroupea] tbody tr").click(function() {

var trArray = $(this); //How to get the TR values here?
alert(trArray);

echo '});

[/code]

Could you please help?

Thanks.

Regards.

Replies

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Use fnGetData - oTable.fnGetData( this );

    Allan
  • KyvuKyvu Posts: 11Questions: 0Answers: 0
    Hello Allan,

    Thank you for your reply but it does not work in my case. When I try to use the object oTable, I get a JS error "oTable is not defined".

    Here is my complete code at now:

    [code]

    $(function(){

    //Init the tabs
    $("#tabs").tabs();

    //Init all HTML tables placed on the tabs
    $("table[id*=mydatatablegroupea]").each(function(){
    var idtable = $(this).attr("id");
    $("#"+idtable).dataTable({
    "bSort": true,
    "aaSorting": [],
    "bPaginate": false,
    "bAutoWidth": false,
    });
    });

    //When clicking on a row of a table, we need to get the TR array values of this specific table
    $("table[id*=mydatatablegroupea] tbody tr").click(function() {
    var trArray = $(this); //How to get the TR values here?
    alert(trArray);
    });

    });

    [/code]

    At once, I can have to generate more than 5 independants HTML tables on the DOM.

    Any idea?

    Thanks.

    Regards.
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Try this rather than oTable (which is my generic variable for storing the table instance in the examples:

    [code]
    $(this).parents('table').dataTable()
    [/code]

    Allan
  • KyvuKyvu Posts: 11Questions: 0Answers: 0
    It's ok now!

    Thank you very much, Allan.
This discussion has been closed.