Is it possible to limit Individual column filtering (select inputs) to specific columns?

Is it possible to limit Individual column filtering (select inputs) to specific columns?

SashaEndohSashaEndoh Posts: 3Questions: 1Answers: 0

The questions says it all: I have a table where I'd like just a few of the columns to be filterable with select inputs. Is it possible to either define the columns I'd like to be filterable or otherwise limit the select input filtering to specific columns?

Thanks so much!

This question has an accepted answers - jump to answer

Answers

  • SashaEndohSashaEndoh Posts: 3Questions: 1Answers: 0
    edited May 2014

    I understand that I can do this with just CSS and hide the select boxes in those columns, but figured I'd see if there's a more eloquent way to do this.

  • RpiechuraRpiechura Posts: 98Questions: 3Answers: 14
    edited May 2014 Answer ✓

    Assuming that you're using the same code that the example does from http://datatables.net/examples/api/multi_filter_select.html than it's pretty simple not to add the box.

    $("#example tfoot th").each( function ( i ) {
    //  if(i==1) {}
    //  else {
        var select = $('<select><option value=""></option></select>')
            .appendTo( $(this).empty() )
            .on( 'change', function () {
                table.column( i )
                    .search( $(this).val() )
                    .draw();
            } );
    
        table.column( i ).data().unique().sort().each( function ( d, j ) {
            select.append( '<option value="'+d+'">'+d+'</option>' )
        } );
     // }
    } );
    

    Obviously you'd uncomment the code that I put in, and change the logic inside the if for whatever columns you want to ignore.

  • SashaEndohSashaEndoh Posts: 3Questions: 1Answers: 0

    Ahh brilliant! Thanks!!

This discussion has been closed.