How to disable a search/filter on a specific column on a datatable?

前端 未结 2 1034
遇见更好的自我
遇见更好的自我 2021-01-01 06:19

My datatable has 5 columns and I need to disable filtering for the 3rd, 4th and last column.

please help!!!

this is the javascript:

2条回答
  •  无人及你
    2021-01-01 07:01

    The same story for columns with filtering. 2nd column filtering disable:

    $(document).ready(function() {
    
    $('#example').DataTable( {
               initComplete: function () {
                this.api().columns().every( function () {
    
                    var column = this;
                    var some = column.index();
                    if (column.index() == 1) return;
                    var 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( '' )
                    } );
                } );
            }})
    };
    

提交回复
热议问题