简体   繁体   中英

how to add filter to datatable

I have made a dataTable and populated it with many fields, but I would like to add my own search/filter function to it.

I have a textbox that I am using as the search/filter:

   <div class="filterTable">
        <form>
            <input id="tableSearch" type="text" placeholder="filter">
        </form>
    </div>

And this is the JavaScript function that I have added for it:

$("tableSearch").keyup(function () {
        var string = document.getElementById("tableSearch").value;
        oTable.fnFilter(string);
    });

oTable is the initialized dataTable.

The problem I am having is that the JavaScript function is never hit. Any Ideas?

You should use the # tag for reffering the ID of an element.

Try with the below mentioned code.

   $("#tableSearch").keyup(function () {
        var string = $(this).val();
        oTable.fnFilter(string);
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM