Datatables Individual Column Search using select input

Datatables Individual Column Search using select input

merlin318merlin318 Posts: 1Questions: 1Answers: 0

Im trying to implement the Individual column sort django. I am able to convert the table into a datatable and the search bar that is displayed works perfectly in searching the table. I modified the code shown in the link mainly to have only only 1 or 2 columns searched via select

However When I select an option form the dropdown the table displays no matching records found , when clearly data matching the criteria exists.

Any help in figuring out the issue will be greatly appreciated. Code is pasted below:

    $(document).ready(function () {
      $('#audience-list').DataTable({
        initComplete: function () {
          this.api().columns([1]).every(function () {
            var column = this;
            var select = $('<select><option value=""></option></select>')
              .appendTo($("#sort"))
              .on('change', function () {
                var val = $.fn.dataTable.util.escapeRegex(
                  $(this).val()
                );
                column
                  .search(val ? '^' + val + '$' : '', true, false)
                  .draw();
              });
            column.data().unique().sort().each(function (d, j) {
              select.append('<option value="' + d + '">' + d + '</option>')
            });
          });
        }
      });
    });
This discussion has been closed.