Filter DataTable with text box

Filter DataTable with text box

panya123panya123 Posts: 3Questions: 1Answers: 0

I'm trying to filter DataTable, with a text box that s not built into datatable functionality. I followed all the instructions but the search[value] is always empty string when I do the keyup function. Following is the code I am using. Thanks in advance.

var table = $("#my-table").DataTable({
"searching": true,
"destroy": true,
"order": [[2, "asc"]],
"processing": true,
"bfilter": false,
"language": {
"processing": "Loading Data... Please Wait"
},
"serverSide": true,
stateSave: false,

    "lengthMenu": [[10, 25, 50, 100], [10, 25, 50, 100]],
    "pagingType": "simple_numbers",
    "info": true,
    "ajax": {
        "url": urlAction,
        "type": "GET",
        "data": {
            "nameCD": nameCode
        }
    },

    "select": {
        "style": "multi"
    },
    "sDom": '<"dt-header font-bold">lrt<"dt-footer"ip>'
});

$('#searchMergeName').on('keyup', function () {
table.columns(2).search(this.value).draw();

});

<input class="form-control" id="searchMergeName" type="search" placeholder="Search Names">

Answers

  • jr42.gordonjr42.gordon Posts: 305Questions: 2Answers: 49
    edited June 2016

    Please see my responses here

  • panya123panya123 Posts: 3Questions: 1Answers: 0
    edited June 2016

    Thanks for the reply but that's not quite what I'm looking for. If you see the image attached, I just have a text box that when I type text in it. Filters the datatable by name column. And the documentation from data table just shows you do the following and it should filter:

    $('#searchMergeName').on('keyup', function () {
    table.columns(2).search(this.value).draw();
    });

    see here:
    https://datatables.net/reference/api/search()

  • jr42.gordonjr42.gordon Posts: 305Questions: 2Answers: 49

    ahh ok I misread your requirement. Give YADCF plugin a look

  • panya123panya123 Posts: 3Questions: 1Answers: 0

    Thanks, this looks like it will work for what I want to do.

This discussion has been closed.