Adding parameters through fnServerParams for tabletools ajax calling

Adding parameters through fnServerParams for tabletools ajax calling

bienvenubienvenu Posts: 1Questions: 0Answers: 0
edited May 2012 in TableTools
Hi everyone,

First of all, I'm french and I am not sure of my english level, so don't worry if I express myself strangely.

I am using Datatables with server-side mode, and I want to use TableTools to create a CSV.
With tabletools basic functions, I only can export the displayed rows and I want to export every data without pagination.
So I tried the "download button" plug-in to realize what I want.

To remember you, the download button code looks like :
[code]
TableTools.BUTTONS.download = {
"sAction": "text",
"sFieldBoundary": "",
"sFieldSeperator": "\t",
"sNewLine": "
",
"sToolTip": "",
"sButtonClass": "DTTT_button_text",
"sButtonClassHover": "DTTT_button_text_hover",
"sButtonText": "Download",
"mColumns": "all",
"bHeader": true,
"bFooter": true,
"sDiv": "",
"fnMouseover": null,
"fnMouseout": null,
"fnClick": function( nButton, oConfig ) {
var oParams = this.s.dt.oApi._fnAjaxParameters( this.s.dt );
var iframe = document.createElement('iframe');
iframe.style.height = "0px";
iframe.style.width = "0px";
iframe.src = oConfig.sUrl+"?"+$.param(oParams);
document.body.appendChild( iframe );
},
"fnSelect": null,
"fnComplete": null,
"fnInit": null
};

[/code]

The problem is that I had some parameters to datatables using "fnServerParams" and it seems like they don't appear in tabletools ajax url.
I've tried to had them directy in oParams in the fnClick function and it works perfecty. But I want to use directly the datatables "fnServerParams" method to modify oParams.

I've tried :
[code]
"fnClick": function( nButton, oConfig ) {
var oParams = this.s.dt.oApi._fnAjaxParameters( this.s.dt );
this.s.dt.fnServerParams(oParams);
var iframe = document.createElement('iframe');
iframe.style.height = "0px";
iframe.style.width = "0px";
iframe.src = oConfig.sUrl+"?"+$.param(oParams);
document.body.appendChild( iframe );
},
[/code]

But the javascript console told me that "fnServerParams" is undefined as a function.
So how can I realize what i want to do ?

Replies

  • drakula1234drakula1234 Posts: 58Questions: 1Answers: 0
    bienvenu ,

    Did you have this figured out ? Even I am facing the same issue. Wondering how to pass the fnServerParams value to my controller
  • phazeiphazei Posts: 3Questions: 0Answers: 0
    I do find myself in the same predicament and would like a to know a solution.

    I don't want to put the data in the plugin itself, since I was going to use it in multiple locations. Even being able to send extra parameters to the click function and have that append it to the query string would be good. I tried just adding a new key in the aButtons array, but it didn't show up in oConfig.

    Any suggestions?
  • phazeiphazei Posts: 3Questions: 0Answers: 0
    Actually, adding the extra data did work:
    In the config:
    [code]
    "oTableTools": {
    "aButtons" : [ {
    "sExtends": "download",
    "sButtonText": "Download CSV",
    "sUrl": "/api/model/",
    "sExtraData": [
    { "name":"data_table", "value":"1" },
    { "name":"csv", "value":"1" }
    ]
    } ]
    }
    [/code]
    And in the plugin:
    [code]
    "sExtraData": [],
    "fnClick": function( nButton, oConfig ) {
    var oParams = this.s.dt.oApi._fnAjaxParameters( this.s.dt );
    oParams = oParams.concat(oConfig.sExtraData);
    var iframe = document.createElement('iframe');
    iframe.style.height = "0px";
    iframe.style.width = "0px";
    iframe.src = oConfig.sUrl+"?"+$.param(oParams);
    document.body.appendChild( iframe );
    },
    [/code]
This discussion has been closed.