fnServerData
fnServerData
Hello all,
First I am more & more impressed by dataTables it really is a superb piece of code! Fairly simple to use once you get you head around it, fast & reliable ... nice one Sir.
Next a quick question, what is the recommended way to return no data from the fnServerData callback.
here is a code fragment from fnServerData
[code]
.....
data.push({name:'SEARCHOPTION', value:so});
data.push({name:'SEARCHVALUE', value:sv});
$.ajax({
"datatype": "json",
"type": "POST",
"global": false,
"url": url,
"data": data,
"success": callback,
"error": function (jqXHR, textStatus, errorThrown)
{
alert (errorThrown);
if (jqXHR.status == 401 )
{
$('#diallogout').click();
LoginLogout();
}
}
.....
[/code]
I need under some circumstances, the ajax call not to be fired, so I need to exit, but want to do this in a graceful way, with the waiting banner properly hidden ...
What is the recommended way ?
thanks in advance
Didier
First I am more & more impressed by dataTables it really is a superb piece of code! Fairly simple to use once you get you head around it, fast & reliable ... nice one Sir.
Next a quick question, what is the recommended way to return no data from the fnServerData callback.
here is a code fragment from fnServerData
[code]
.....
data.push({name:'SEARCHOPTION', value:so});
data.push({name:'SEARCHVALUE', value:sv});
$.ajax({
"datatype": "json",
"type": "POST",
"global": false,
"url": url,
"data": data,
"success": callback,
"error": function (jqXHR, textStatus, errorThrown)
{
alert (errorThrown);
if (jqXHR.status == 401 )
{
$('#diallogout').click();
LoginLogout();
}
}
.....
[/code]
I need under some circumstances, the ajax call not to be fired, so I need to exit, but want to do this in a graceful way, with the waiting banner properly hidden ...
What is the recommended way ?
thanks in advance
Didier
This discussion has been closed.
Replies
I'm wondering if it might be worth introducing a pre-draw function which could be used to prematurely stop the draw, as I know that this has come up before - I'm just slightly concerned about adding more and more configuration options!
Allan
So what about setting a separate callback fonction which would return a dummy json resultset (same sEcho as the one send, iTotalRecord & iTotalDisplayRecords set to 0 and aaData to [];
If this works, you would not need to modify dataTables at all, just explain the 2 questions at the end of this post
[code]
function dummycallback ()
{
setup a dummy array
}
[/code]
and in fnServerData I could then do something like
[code]
....
var mycallback = (Logic_deciding_to_get_the_date) ? callback : dummycallback;
$.ajax({
"datatype": "json",
"type": "POST",
"global": false,
"url": url,
"data": data,
"success": mycallback,
....
[/code]
Would that be silly ?
Note that I am note sure where to get the sEcho value from not the exact parameters for the callback fonction, it is just an idea.
Didier
I had wondered about something like that as well - but I think it would probably need a fair amount of support code to do, in order to get it reliability working, for what is a fairly unusual use case.
What I have done however is to commit a new feature to DataTables which allows a new callback function called fnPreDrawCallback - which is called at the very start of a draw. If your function returns false, then the draw is cancelled - otherwise it continues on. Hopefully this will be of some use to you.
Regards,
Allan
[edit] done and used the opportunity to have a go at 1.8 (current nightly) and so far I have seen no obvious regression and get the feeling that speed has improved
I implemented the new option you commited and it works a treat.
Didier
Allan