column filtering using dropdown - how to confine to some columns only

column filtering using dropdown - how to confine to some columns only

hbanaharishbanaharis Posts: 32Questions: 14Answers: 3

Im using this code to generate a dropdown filter for each column.

this.api().columns().every( function () {
                var column = $(this).class('filterhead');
                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 value="'+d+'">'+d+'</option>' )
                } );
            } );

How can I apply it only to selected columns ie based on the footer th class?

Answers

  • hbanaharishbanaharis Posts: 32Questions: 14Answers: 3

    use this.api().columns( a )
    where a = sequence of columns
    eg if columns 3,4 and 5 then a = '3,4,5'

This discussion has been closed.