Custom filter option and server-side processing.
Custom filter option and server-side processing.
Hi.
First of all thanks for the awesome component :)
We have a grid with paging and sorting on the page, which requires addition custom filtering. We cant use standard filtering textbox, so we placed our own controls (checkboxes) above grid. Is there any way to intercept ajax url, which uses by datatables to retrieve information from server, and add additional "get" field to request?
First of all thanks for the awesome component :)
We have a grid with paging and sorting on the page, which requires addition custom filtering. We cant use standard filtering textbox, so we placed our own controls (checkboxes) above grid. Is there any way to intercept ajax url, which uses by datatables to retrieve information from server, and add additional "get" field to request?
This discussion has been closed.
Replies
Yup - there certainly is. What you need to do is override the built in get function by using the parameter 'fnServerData' - I'm afraid that this isn't fully documented yet since it's only in 1.5 beta (need to update the documentation for 1.5 final), but what you can do is something like this:
[code]
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "media/examples_support/server_processing.php",
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.push( { "name": "more_data", "value": "my_value" } );
// etc
$.getJSON( sSource, aoData, function (json) { fnCallback(json) } );
}
} );
} );
[/code]
There is a little bit more detail about this function override in this thread: http://datatables.net/forums/comments.php?DiscussionID=53 - but this example will hopefully point you in the right direction :-)
Allan
One more question. Is it possible to determine filter value for the specified column? And how if possible?
And last thing, well its just more like a suggestion... It would be really cool (maybe optionaly) if indexed variables of ajax Url appear like 'name[i]' instead of 'name_i'. Both aspnet mvc and monorail have array parameter binders, so it would be possible to have server actions like
public JsonResult GetData(int iColumns, bool[] bEscapeRegex, int[] iSortCol, int[] iSortDir, string[] sSearch)
{
for (int i = 0; i < iColumns; i++){
string s = sSearch[i];
// etc...
}
}
instead of loooong action parameter list.
Please consider this only as a suggestion, and thanks for the excelent work :)
PS. Excuse my poor english.
Is there any callback function, which fires right after table's dom created? I tried fnInitComplete, but seems it fires only after initialization from html markup, and not from ajax response. I'm asking because i'm trying to marry datatables with tableDnD plugin, and tableDnD requires complete built table, which datatable builds after ajax response.
1. The individual filter column information should be passed to you by the Ajax call. You should get:
sSearch_(int) - Individual column filter
bEscapeRegex_(int) - Individual column filter is regex or not
for each column - which will tell you the search information for each one.
2. I'm somewhat reluctant to include language specific information in the http variables. Although the current method might require a little bit of processing on each platform, it is at least not-platform specific. Also, I'm weary of including language syntax in http vars... Sounds like a possible security risk.
3. When using the server-side processing option, the fnDrawCallback function is called on each draw (i.e. whenever the DOM is recreated).
Regards,
Allan
Allan