Is there any contract when overriding "fnServerData" in dataTable settings
Is there any contract when overriding "fnServerData" in dataTable settings
Hi Allan,
When I looked into the comments for "fnServerData" callback and the source code of the default one provided in dataTable.defaults, I am not sure if we have to adhere to any contract when providing this callback in my own dataTable settings, such as:
[code]"fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
// ...
}[/code]
1. Do I need to explicitly invoke fnCallback(json) in $.ajax success callback?
2. Do I need to explicitly trigger “xhr" event in $.ajax success callback?
[code]$(oSettings.oInstance).trigger('xhr', [oSettings, json]);[/code]
3. Do I need to set oSettings.jqXHR?
4. Anything else I need to pay attention to / adhere to?
5. Any best practice to provide this option in dataTable settings?
Thanks & regards,
Roy
When I looked into the comments for "fnServerData" callback and the source code of the default one provided in dataTable.defaults, I am not sure if we have to adhere to any contract when providing this callback in my own dataTable settings, such as:
[code]"fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
// ...
}[/code]
1. Do I need to explicitly invoke fnCallback(json) in $.ajax success callback?
2. Do I need to explicitly trigger “xhr" event in $.ajax success callback?
[code]$(oSettings.oInstance).trigger('xhr', [oSettings, json]);[/code]
3. Do I need to set oSettings.jqXHR?
4. Anything else I need to pay attention to / adhere to?
5. Any best practice to provide this option in dataTable settings?
Thanks & regards,
Roy
This discussion has been closed.
Replies
Yes - absolutely. The callback is what redraws the table.
> 2. Do I need to explicitly trigger “xhr" event in $.ajax success callback?
If you aren't listening for 'xhr', then no. DataTables doesn't use it internally.
> 3. Do I need to set oSettings.jqXHR?
Strictly speaking - no. But it can be useful for debugging since it provides a back reference.
[quote]
4. Anything else I need to pay attention to / adhere to?
5. Any best practice to provide this option in dataTable settings?
[/quote]
Only override if you have to. Use fnServerParams to add parameters to what is sent to the server, and sServerMethod to change to POST. If you need something beyond that, then the key thing is simply to call the callback method.
Allan
Thanks a lot for your answers!