dropdowns ONLY for some columns

dropdowns ONLY for some columns

muscaiumuscaiu Posts: 6Questions: 4Answers: 0

Using this code, and all examples i've seen, i can add dropdowns to ALL columns like in the picture:

https://drive.google.com/file/d/0B4nUvzf87W8KVzRVY0daZXhmcjg/view

var table = $('#myTable').DataTable({
        dom: 'lfBrtip',

        initComplete: function () {
        this.api().columns().every( function () {
            var column = this;
            var select = $('<select><option value=""></option></select>')
                .appendTo( $(column.header()))
                .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 add dropdowns ONLY for column 2 and 3 for example?
Thank you.

Answers

  • scholarlylabsscholarlylabs Posts: 16Questions: 0Answers: 2

    You can apply the dropdown filters to particular columns pretty easily:

    1. Add a class to the columns where you want the filters. You can do this in the js by adding ...className: "whatever_class_name_you_want"... to your column definitions.
    2. Add this class identifier to the function that adds the filters. In your code above, change row 5 from this.api().columns().every( function () { to this.api().columns('.whatever_class_name_you_want').every( function () {
This discussion has been closed.