search in Header

search in Header

antoniocibantoniocib Posts: 277Questions: 62Answers: 1
$('#scadenze thead th').each( function () {                                                                                                                                                                         
var title = $(this).text();                                                                                                                                                                                                         
$(this).html( '<input type="text"  style="text-align:center ; width:100%" placeholder="'+title+'" />' );                                                    
} );

var table = $('#scadenze').DataTable();

table.columns().every( function () {
var that = this;

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

table.on('select deselect', function () {
table.draw(false);
});
} );

I have implemented the search in the header of the table but I don't want it for all the columns how can I customize it?

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,991Questions: 87Answers: 421

    by assigning a class to the respective td element and then using the class in your JS.

    ....
    initComplete: function () {
        var table = this.api();
        $('.filterHead', table.table().header()).each( function (i) {
    ....
    
  • antoniocibantoniocib Posts: 277Questions: 62Answers: 1

    @rf1234 can you explain it better?

  • rf1234rf1234 Posts: 2,991Questions: 87Answers: 421
    Answer ✓

    You assign the class to the columns you want column search to work and you don't assign the class to those columns that shouldn't be column searchable.

Sign In or Register to comment.