rentageekmom of LDM Devs
3/14/2017 - 12:22 PM

DataTables Column Filtering

DataTables Column Filtering

$('#example').dataTable( {
  "initComplete": function () {
     {this.api().column(4).every( function () {
         var column = this;
         var select = jQuery('<select><option value=""></option></select>')
         .appendTo( jQuery(column.header()).empty() )
         .on( 'change', function () {
             var val = jQuery.fn.dataTable.util.escapeRegex(
                 jQuery(this).val()
             );

             column
                 .search( val ? '^'+val+'$' : '', true, false )
                 .draw();
         });

         column.data().unique().sort().each( function ( d, j ) {
             select.append( '<option value="'+d+'">'+d+'</option>' )
         });
        });
      }  
    }
});