Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82293

How to resize columns with DataTables with the search inputs into the table header?

$
0
0

Hi! I would like to know how can I make an auto-sizing of my table columns when I add search inputs into the table header.

By the time the column width is fixed at 169px (probably due to the search inputs) and I don't know how to resize it (so it can fit to my data).

Can you help me please?

$(document).ready(function() {
    // Setup - add a text input to each header cell
    $('#maTable thead .search').each( function () {
        var title = $('#maTable thead .header_title').eq( $(this).index() ).text();
        $(this).html( '<input type="text" placeholder="Search '+title+'"/>' );
    } );
 
    // DataTable
    var table = $('#maTable').DataTable();
    
    // Apply the search
    table.columns().every( function () {
        var that = this;
        
        $( 'input', this.header() ).on( 'keyup change', function () {
            that
                .search( this.value )
                .draw();
        } );
    } );
});

Viewing all articles
Browse latest Browse all 82293

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>