How to make filter only for 2,3 and 5 column?

How to make filter only for 2,3 and 5 column?

Vladimir PotapovVladimir Potapov Posts: 2Questions: 1Answers: 0

Please, help me make filter like it make in exapmle, but only for 2,3 and 5 columns:
https://datatables.net/examples/api/multi_filter_select.html

I'm really do not know how to make it.
Thank you.

Answers

  • kthorngrenkthorngren Posts: 20,396Questions: 26Answers: 4,786

    One way is to assign a classname to each column you want to apply the search. This example is for text inputs but the same idea should work for select inputs.

    http://live.datatables.net/vuruhosa/1/edit

    Kevin

  • Vladimir PotapovVladimir Potapov Posts: 2Questions: 1Answers: 0

    I found the case:
    take a look at "i" variable

         $('#mytable').DataTable( {
    
        initComplete: function () {
            this.api().columns().every( function (i) {
                 (i == 2 || i == 4 || i == 5 || i == 6 )
                var column = this;
    
                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>' )
                } );
                }
            } );
        }
    } );
    
This discussion has been closed.