Create new set of data from existing table with search applied

Create new set of data from existing table with search applied

mosleymosley Posts: 8Questions: 4Answers: 0

I am trying to populate a second table, from a new set of data created from an existing table, which has a search applied to it. I only want the rows that are revealed from the search.

With regards to the DataTables Live example below there are 57 rows of data. I search (filter) the first table to column 2 'Edinburgh', which reveals 19 rows. I want to create a new set of data that ONLY has the 19 rows, then populate a second table.

This seems possible from reading the documentation and some of the forum threads (specifically this one), but I am not sure what I am doing wrong.

http://live.datatables.net/varomafe/1/edit

Thanks.

Answers

  • mosleymosley Posts: 8Questions: 4Answers: 0

    OK, I just looked closer at the forum thread in my post above. I added toArray() to the end of

      var filteredData = table.rows( { search: 'applied' } ).data();
    

    and removed data() from

      table2.rows.add( filteredData.data() ).draw();
    

    and it works. So rows().data().toArray() stores only visible rows in a Javascript array, but whats going on with the Datatables API instance?

This discussion has been closed.