Filtering data in one table by clicking on a row in another

Filtering data in one table by clicking on a row in another

noob123noob123 Posts: 3Questions: 1Answers: 0

I have two AngularJS DataTables displayed. First one with counties and second with towns. So, what I need to do is filter data in second table by clicking a row in first table. For example, when I click on row with Orange County in first table, in second should be filtered only tawns from that county, not other ones. Any suggestions and pointers on how to do that would be highly appreciated.

This question has an accepted answers - jump to answer

Answers

  • cpowercpower Posts: 11Questions: 3Answers: 2
    edited May 2015 Answer ✓

    Where does the data come from for both tables?
    What I would do is wiring a click handler on the row to retrieve/refresh the data for the second table. Something like this:

    var table1 = $('#t1').DataTable();
    var table2 = $('#t2').DataTable();
    table1.on('click', 'tbody tr', function () {
    //get the row data
    var country = table1.row( this ).data();
    table2.clear();
    var data = private_GetTowns(country);
    table2.rows.add(data);
    table2.draw();
    });
    
  • noob123noob123 Posts: 3Questions: 1Answers: 0

    I have two controllers, in first i reach data from county table and in second i reach for towns data from towns table. Then I display them both in same HTML page, in two separate div tags. One div using first controller, and another using second controller. I suppose I should first somehow enable transfering data from one controller to another.

  • noob123noob123 Posts: 3Questions: 1Answers: 0

    Thank you this worked :)

This discussion has been closed.