Dynamically Load Joined Table

Dynamically Load Joined Table

3phi3phi Posts: 5Questions: 1Answers: 0

Take this example: https://editor.datatables.net/examples/inline-editing/join.html

I'd like to add a drop list for "Countries" outside of the table and when the user selects a country the Location drop-list inside the table automatically reloads itself to only display the list of cities for the selected country.

I know how to load the initial list of cities via ajax but how do I update the Location drop-list once the table is created?

Thanks,

PT

Replies

  • allanallan Posts: 61,732Questions: 1Answers: 10,110 Site admin

    Hi PT,

    Use ajax.data to send the data to the server (used by the server to filter to the required country) and ajax.reload() to trigger the reload - e.g.:

    let table = $('#myTable').DataTable({
      ajax: {
        url: '...',
        data: d => d.country = $('#countrySelect').val()
      }
    });
    
    $('#countrySelect').on('change', () => table.ajax.reload());
    

    Allan

Sign In or Register to comment.