Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a column for percentage completion in my table and I have column filtering available on it of type 'select'. I want my drop down filter to display a static list of brackets (like <20%, 20-60% and >60%). So that when a user selects that filter option the data table only displays those rows.
Her is my code till now:

 $(document).ready(function() {
  $('#OpptyTable').DataTable({
    "sDom":"ltipr" ,
    "pageLength": 25,    
    initComplete: function() {
      this.api().columns([1,2,3]).every(function() {
        var column = this;
        var select = $('<select><option value=""></option></select>')
          .appendTo($(column.footer()).empty())
          .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 >' + d + '</option>');
        });
      });

      this.api().columns([0]).every(function() {
        var that = this;
        var input = $('<input type="text" placeholder="Search" />')
          .appendTo($(this.footer()).empty())

          .on('keyup change', function() {
            if (that.search() !== this.value) {
              that
                .search(this.value)
                .draw();
            }
          });
      });
      var r = $('#OpptyTable tfoot .filterAvailable');
  r.find('th').each(function(){
    $(this).css('padding', 8);
  });
  $('#OpptyTable thead').prepend(r);
  $('#search_0').css('text-align', 'center');
    }
  });
});


What I have tried:

Code mentioned in the problem description
Posted
Comments
[no name] 27-Aug-19 11:04am    
I wish I could say something positive but I can't; but thanks for showing me why I will never learn JQuery or any of its spawn. A "table" with a "string to display" and 2 values for a range comes to mind, but it looks like that is a foreign concept in "JQuery" (non-query?)
Richard Deeming 27-Aug-19 12:13pm    
Sounds like you want to adapt the "customer filtering" example:
DataTables example - Custom filtering - range search[^]
ZurdoDev 3-Sep-19 16:23pm    
I don't understand your question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900