Serverside filtering with intial column filter
Serverside filtering with intial column filter
I've got server side filtering working with text boxes to search on individual columns and it works great to filter after the initial table draw.
However, I'd like to be able to provide an initial search term in the URL. e.g. page.html?person_id=123456
then populates the columns text box, and hence the server query. At the moment I can do it like:
[code]
$(document).ready(function(){
nTable = $('#notifications').dataTable({
"aoColumnDefs": [
{ "bSortable": false, "aTargets": [ 0 ] }
],
"aaSorting": [[1, 'desc']],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "https://server/getNotifications",
"fnDrawCallback":redraw
});
if ($.url.param("person_id")) {
$("#n_personid_filter").val($.url.param("person_id"));
nTable.fnFilter( $.url.param("person_id"), 2 );
}
[/code]
This works, but it is messy because it actually draws the table, then redraws it with the filter so makes 2 ajax calls.
Is there a way of providing an initial column filter (i.e. not a global one using oSearch) before initialising datatables?
cheers!!
Mark
However, I'd like to be able to provide an initial search term in the URL. e.g. page.html?person_id=123456
then populates the columns text box, and hence the server query. At the moment I can do it like:
[code]
$(document).ready(function(){
nTable = $('#notifications').dataTable({
"aoColumnDefs": [
{ "bSortable": false, "aTargets": [ 0 ] }
],
"aaSorting": [[1, 'desc']],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "https://server/getNotifications",
"fnDrawCallback":redraw
});
if ($.url.param("person_id")) {
$("#n_personid_filter").val($.url.param("person_id"));
nTable.fnFilter( $.url.param("person_id"), 2 );
}
[/code]
This works, but it is messy because it actually draws the table, then redraws it with the filter so makes 2 ajax calls.
Is there a way of providing an initial column filter (i.e. not a global one using oSearch) before initialising datatables?
cheers!!
Mark
This discussion has been closed.
Replies
Allan
I read the docs backwards and forwards but only found oSearch...
thanks!