Searchable columns but remove from certain columns

Searchable columns but remove from certain columns

davidjmorindavidjmorin Posts: 101Questions: 31Answers: 0

I love the search column feature. One issue I have though is what if I want to remove that function from col 0,3,9,10? How would I do that with the below script?

  <script type="text/javascript" class="init">
        $(document).ready(function() {
          // Setup - add a text input to each footer cell
          $('#rq tfoot td').each( function () {
              var title = $(this).text();
              $(this).html( '<input type="text" placeholder="Search '+title+'" />' );
          } );

        $(document).ready(function() {
            $('#rq').DataTable( {
              scrollY:        2000,
              scrollX:        true,
              scrollCollapse: true,
              fixedColumns:   true,
              "dom": '<"toolbar">frtip',
                "order": [[ 3, 'desc' ], [ 2, 'asc' ]],
                lengthChange: true,
                pageLength: 25,
                dom: '<"top"i>rt<"bottom"flp><"clear">',
                dom: 'Bfrtip',
                pagingType: "full_numbers",
                "language": {
                              "emptyTable": "<b><h3>Select a date range from above</h3></b>"
                            },
                                        buttons: [
                    { extend: 'csvHtml5',
                    footer: true,
                    text:   'Export',
                    filename: function(){
                               var d = new Date();
                               month = '' + (d.getMonth() + 1),
                               day = '' + d.getDate(),
                               year = d.getFullYear();
                               var n = d.getTime();
                               var now = new Date();
                               var months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'];
                               var formattedDate = now.getFullYear() + months[now.getMonth()] + now.getDate();
                               return formattedDate + '_VZW_Activations_Discrep_RQ'}

                   },
                ],
                initComplete: function () {
                            // Apply the search
                            this.api().columns().every( function () {
                                var that = this;

                                $( 'input', this.footer() ).on( 'keyup change clear', function () {
                                    if ( that.search() !== this.value ) {
                                        that
                                            .search( this.value )
                                            .draw();
                                    }
                                } );
                            } );
                        }
                    });

            } );
        } );


          </script>

http://live.datatables.net/fevinave/1/edit?html,js,output

This question has an accepted answers - jump to answer

Answers

  • davidjmorindavidjmorin Posts: 101Questions: 31Answers: 0

    Picture for illustration purposes

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923

    The columns() API can take different column-selector options you can use. You can pass an array with column indexes. You can add a class to the columns you want searchable and pass that.

    Kevin

  • davidjmorindavidjmorin Posts: 101Questions: 31Answers: 0

    Im sorry, in my image i meant to say i need to remove that search box from the column. Not the whole column.

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923
    Answer ✓

    this.api().columns().every( function () {

    In the above line use column-selector as I described above to loop through only the desired columns.

    Kevin

This discussion has been closed.