Remove a text input in first header cell Datatable

Remove a text input in first header cell Datatable

zhurb21zhurb21 Posts: 12Questions: 5Answers: 0

How to remove a text input in first header cell?
Found some solutions here, but they just don't work.

Thank you for your help.

$('#myTable thead tr').clone(true).appendTo( '#myTable thead' );
$('#myTable thead tr:eq(1) th').each( function (i) {
var title = $(this).text();
$(this).html( '<input type="text" placeholder="'+title+'" />' );
$( 'input', this ).on( 'keyup change', function () {
if ( table.column(i).search() !== this.value ) {
table
.column(i)
.search( this.value )
.draw();
}
} );
} );

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599
    Answer ✓

    You're going through all the <th>s in your loop on the second line - so just skip that first header with something like:

    $('#myTable thead tr:eq(1) th:not(:first-child)').each( function (i) {
    

    Colin

  • zhurb21zhurb21 Posts: 12Questions: 5Answers: 0

    Thank you, Colin. This solution is work, but crash the search inputs for other columns.

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.