How can I get all data in this case?

How can I get all data in this case?

HokwangHokwang Posts: 8Questions: 4Answers: 0

Hello.

I make a table like http://live.datatables.net/bazilay/1.

There are <select> in table.
In this case how can I get all data in table?
I want to send table data using ajax to another page.

I am using latest version of datatable.

I am thinking about..

$("#table").row().each(function() {
 data[] = [$(this).children("td:first-child").val(), $(this).children("td:nth-child(2)").val(), $(this).children("td:last-child").text()];
});

Thank you in advance.

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited July 2014 Answer ✓

    There are a number of ways to do it, but this one is fairly succinct:

    $('select', table.rows().nodes())
    

    i.e. get the tr nodes for all rows using rows().nodes() and then use jQuery to get the select elements.

    Allan

  • HokwangHokwang Posts: 8Questions: 4Answers: 0
    edited July 2014

    Thank you. allan.

    But, please show more detail.

    How can I send all data to another page?
    There are 2 (or more) rows and 2 (or more) collunms..
    count of rows will be changed.

    I successed getting one select val using

    var one = $('select', table.rows().nodes()).val();
    

    but I need all data..

    data = ???;
    
    
    $.ajax({
      ...
      data: "table_info=" + data,
      ...
    });
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    What do you mean a different page? A pop up window, a reloaded page, or an Ajax call like you have above?

    For each of those, those are general javascript questions and you might be best to ask on SO or similar. The above code will get the select elements from the table, and you can then use jQuery's map method, or similar, to build an array of values.

    Allan

This discussion has been closed.