Target column filter inputs only

Target column filter inputs only

NoBullManNoBullMan Posts: 87Questions: 24Answers: 2

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
I use the following to clear input elements in column filter of header but this targets all input fields on the page and clears them all.

Is there a way to just target those elements in header column?

function clearTable(){
    myTable.clear().search('').draw();
    myTable.columns().search('').draw();

    $('.filter th').each(function (i) {
        $("input[type='text']").each(function (){
            $(this).val('');
        })
    });
}

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 64,223Questions: 1Answers: 10,598 Site admin
    Answer ✓
    $("input[type='text']")
    

    should be:

    $("input[type='text']", this)
    

    That will limit the search to your found th elements. Otherwise it is just operating globally (multiple times).

    Allan

  • NoBullManNoBullMan Posts: 87Questions: 24Answers: 2

    Thank you Allan,

Sign In or Register to comment.