Is there any contract when overriding "fnServerData" in dataTable settings

Is there any contract when overriding "fnServerData" in dataTable settings

RoyLingRoyLing Posts: 26Questions: 0Answers: 0
edited November 2012 in General
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

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    > 1. Do I need to explicitly invoke fnCallback(json) in $.ajax success callback?

    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
  • RoyLingRoyLing Posts: 26Questions: 0Answers: 0
    Allan,

    Thanks a lot for your answers!
This discussion has been closed.