Hi, I'm trying to implement column filter but it is not working.

Hi, I'm trying to implement column filter but it is not working.

ankur128ankur128 Posts: 1Questions: 1Answers: 0

(Start code)
$(document).ready(function() {
$('#data-table').DataTable( {
"sPaginationType": "full_numbers",
"bStateSave": true,
"ajax": "http://beta.json-generator.com/api/json/get/41ZMGWS17",
"columns" : [
{ "data" : "name" },
{ "data" : "gender" },
{ "data" : "designation" }
],
"initComplete": function () {
this.api().columns().every( function () {
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo( $(column.footer()).each() )
.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>' )
                } );
            } );
        },
    } );
} );

(End code)

Answers

  • pratsprats Posts: 45Questions: 21Answers: 0
  • allanallan Posts: 63,889Questions: 1Answers: 10,530 Site admin

    Thanks for your question - however, per the forum rules can you link to a test case showing the issue please. This will allow the issue to be debugged.

    Information on how to create a test page, if you can't provide a link to your own page can be found here.

    Thanks,
    Allan

This discussion has been closed.