How to set value for Jquery Datatables filter?

Asked

Viewed 665 times

2

I have my input and button

<input id="gridSearch" type="text" /> <button id="filter" class="btn btn-default">Buscar</button>

and my table

$.fn.dataTable.ext.legacy.ajax = true;
var grid = $("#gridCustomer").DataTable({
    "language": {
        "sProcessing": '<img src="/Scripts/loadingBgBlack.GIF" /> Loading...'
    },
    "bFilter": false,
    "bLengthChange": false,
    "processing": true,
    "serverSide": true

How do I select the value to filter in the grid ?

$('#filter').click(function (e) {

    var searchValue = $("#gridSearch").val();

});

Why did I do it?

Why I want to put the input in another position, and I want it to look only when I click "Search".

So I removed what comes standard, using "bFilter": false and manually adding my own input with button

1 answer

1

Friend.

In order for you to do this, you will have to pass the value of your field to the source that is loading the information.

In my case I use PHP to load the information. In PHP Font there is a $_GET ['sSearch'] which is the value of the Default field.

Just replace it with the value of the field you are using - &sSearch=SEU_VALOR

Browser other questions tagged

You are not signed in. Login or sign up in order to post.