Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using DataTables[^] to draw my data. Also I am using OData filter to show only those rows which I need, by several conditions.

JavaScript
var dtApi = new $.fn.dataTable.Api("#CardsGrid_grid");
...
filter assing (for example: "Status eq 0" and...)
...
dtApi.draw();

It works fine. I am receiving what I need. Now I need find and show only those rows which values (one of them) contains a value from textbox.

So... according to this link[^],
JavaScript
column().search(value)
should do the thing, and this supposed to look like:

JavaScript
var search = $("#searchInTable").val();
dtApi.column().search(search).draw();

but the thing is that this do nothing. At all. I assume that I doing it wrong, or maybe because I am using OData (and as a result, dtApi.rows().filter also not reaction on anything).

How can I use search correctly?
Posted

1 solution

Hi,

I've not used the DataTables API (like you posted above), but if you are looking to search a specific column then I would do it like:

JavaScript
//Global variable for DataTable ... 
var dt;

//Create your DataTable ... 
function createDataTable(){
 dt = $('#CardsGrid_grid').DataTable();
}

//Search DataTable ... 
function searchDataTable(search){
    dt.columns(2).search(search).draw();
}


The above example searches the 2nd columns in your table.

... hope it helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900