Server-Side Search/Filter Help
Server-Side Search/Filter Help
So here's my scenario. I am using DataTables with server-side processing. I have a number of columns in the table and have filters set up for each column. Specifically, select multiple drop-downs. A user sets the various filters and then hits an "Apply" button. Once applied, a function is called and the following code is executed to perform the search and return the filtered results.
$('.dt-search').each(function(i, el){
var colName = $(el).attr('dt-search-name');
var searchValue = $(el).val();
table.column(colName + ":name")
.search( searchValue, false, false )
.draw();
});
Now, it works fine. However, the ajax call that fetches the data for the table gets called multiple times - once for each drop-down tied to a column filter. So if I have 8 columns and an input tied to each column as a filter. I would see 8 ajax calls where the first call includes the filter from the first input, the second call would include the filters from the first two inputs, etc.. I mean this makes sense because I am iterating through each input. However, this does not seem ideal. I would prefer to limit the number of server calls...especially when working with large numbers
Is it possible to aggregate all the search criteria first and then submit a single ajax call? Seems like as soon as I call the .search() function, the ajax call gets made.
Thanks,
This question has an accepted answers - jump to answer
Answers
Call
draw()
method after theeach()
function:See more articles about jQuery DataTables on gyrocode.com.