Update dropdown select after ajax reload or setting filter

Update dropdown select after ajax reload or setting filter

martin1223345martin1223345 Posts: 83Questions: 22Answers: 0

Link to example: live.datatables.net/lomevebo/1/edit

I am searching for a way to do 2 things.

1 I need the other select boxes to be updates after one is selected so the other option reduce as they are no longer relevant after selecting. For example I have a colomn with 100 clients and a colomn with months. When I select the month I only need to see the clients presented in that month and visa versa.

2 After I use a update statement from a other ajax submit and call the function: $('#example').DataTable().ajax.reload(null, false); I need the values in the dropdowns to be updated with the new results.

I have been searching and found the folowing example for questions 1. live.datatables.net/jusidipo/1/edit but i cant get this intergrated in my project/code in the example i got. Is there a simperler way to do this?


  • kthorngrenkthorngren Posts: 15,824Questions: 25Answers: 3,751

    Allan's example from this thread is probably easier to implement. I made two changes to your initComplete code. First this:

    var column = table.column( this, {search: 'applied'} );;

    and this, added .empty():

    .appendTo(  $('thead tr:eq(1) th:eq(' + this.index()  + ')').empty() )

    Looks like it works here but I haven't tested thoroughly:


  • martin1223345martin1223345 Posts: 83Questions: 22Answers: 0

    Hey Kevin,

    Thank you for responding. I have a hard time implenting you answer to my project(not a expiernced developer..). See my complete datatable code (example is not running ofcourse, i have no idea how to make a demo for a code as this..).

    Where and how do I implent that solution in the code as shown in below link?


  • martin1223345martin1223345 Posts: 83Questions: 22Answers: 0

    Tried to use your changes to the initcomplete code. Gives the folowing error.

    Uncaught TypeError: table.column is not a function

  • colincolin Posts: 14,213Questions: 1Answers: 2,408

    I suspect it's because you haven't set the variable table. Try this as the first line in your initComplete function:

    var table = this.api();

    If that doesn't help, please update the test case to demonstrate the issue,


  • martin1223345martin1223345 Posts: 83Questions: 22Answers: 0

    Thanks. That seems to work for the changes Kevin proposed. I actualy dont understand what it is suppose to do. As after reload the filter is not refreshed. I did managed to implent the example for question 1 but that kills performance for my project so left that out. So all I use now is the initcomplete function as in the below example. So how to make it reload filter after calling $('#example').DataTable().ajax.reload(null, false);


Sign In or Register to comment.