How to allow plugins to add ServerParams?

How to allow plugins to add ServerParams?

samvdbsamvdb Posts: 8Questions: 0Answers: 0
edited August 2013 in Plug-ins
Hi,

I'm currently trying to implement a custom server-side filtering method. (eg. send date range to the server when filtering).
I was thinking about adding a new variable to the "aoData" to explain my intention to the server.
I know i can do this in the datatable configuration using the "fnServerParams" setting. What i don't understand is how multiple plugin's can modify this.
For instance i have 2 plugin's who want to add something to the aoData. If i declare 1 closure to fnServerParams i have to type the logic in my datatable configuration instead of the seperate plugin file. I don't want to do this since im planning on creating alot of small plugins for the filtering. They all might need to add some data for the server.

[code]
var oTable = $('#example').dataTable({
'fnServerParams': function ( aoData ) {
aoData.push( { "name": "filter", "value": "more" } );
},
}
[/code]
The code above works fine, but i want several plugins to do the same. How can i do this?

Also i'm not sure what the code below does.
From what i understand is that _fnCallbackfire trigger's an event on the datatable instance with the name "serverParams". What i cant find is where this event is intercepted. What piece of code triggers the "fnServerParams" closure in the settings?
[code]
/**
* Add Ajax parameters from plug-ins
* @param {object} oSettings dataTables settings object
* @param array {objects} aoData name/value pairs to send to the server
* @memberof DataTable#oApi
*/
function _fnServerParams( oSettings, aoData )
{
_fnCallbackFire( oSettings, 'aoServerParams', 'serverParams', [aoData] );
}
[/code]

Thanks!

Edit: I can upgrade to 1.10 beta in case a good solution can be found there. I'm exploring the source now.

Replies

  • samvdbsamvdb Posts: 8Questions: 0Answers: 0
    Update:
    When implementing a new feature i managed to push a closure to aoServerParams. Is this the correct way to do this?

    [code]
    $.fn.dataTableExt.aoFeatures.push({
    "fnInit": function (oDTSettings) {
    console.log('init');

    oDTSettings.aoServerParams.push({
    "fn": function(aoData) {
    aoData.push({"name": "filter", "value": "fffmore"});
    },
    "sName": "addParams"
    });
    console.debug(oDTSettings.aoServerParams);

    // new DT_pagingControl(oDTSettings);
    },
    "cFeature": "S",
    "sFeature": "SamControl"
    });
    [/code]
  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    Yes indeed - that absolutely is the way to do it :-)

    Allan
This discussion has been closed.