hide columns in datatables using individual column searching

hide columns in datatables using individual column searching

Ali-aatiAli-aati Posts: 8Questions: 3Answers: 0

I need to hide two columns (1,2) like in picture. How can do that please I need help.

this my example
http://live.datatables.net/piqidoqo/610/edit

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Hi @Ali-aati ,

    Do you want to hide the column (column().visible()), or just no search box (then don't create it for that column - check the index in your code).

    Cheers,

    Colin

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Duplicate of this thread - please only post once.

  • Ali-aatiAli-aati Posts: 8Questions: 3Answers: 0
    edited October 2018

    Hi @colin I just want to remove the search box for the column 1,2. How I can do it?

             ​$('#example').dataTable( {
                "lengthChange": false,  
               "filter": false
    
              });
    
            // Setup - add a text input to each header cell
            $('#example thead tr:eq(1) th').each( function () {
                var title = $('#example thead tr:eq(0) th').eq( $(this).index() ).text();
                $(this).html( '<input type="text" class="form-control" />' );
            } ); 
    
            var table = $('#example').DataTable({
                orderCellsTop: true
            });
    
            // Apply the search
            table.columns().every(function (index) {
                $('#example thead tr:eq(1) th:eq(' + index + ') input').on('keyup change', function () {
                    table.column($(this).parent().index() + ':visible')
    
                        .search(this.value)
                        .draw();
                });
            });
    
  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    Answer ✓

    Hi @Ali-aati ,

    I would suggest doing something like this - since as you've probably noticed with your code, when you click in your input box it reorders the table.

    Cheers,

    Colin

  • Ali-aatiAli-aati Posts: 8Questions: 3Answers: 0

    Thank so much @colin

This discussion has been closed.