Table Tools Download plugin with custom params

Table Tools Download plugin with custom params

jrizzi1jrizzi1 Posts: 44Questions: 12Answers: 3
edited June 2013 in TableTools
I am almost there i just need a slight push

I have a custom parameter i send to my datatable server side calls, and i would also like to send it to my table tools custom button

I am attempting modifying code from a separate forum post here http://datatables.net/forums/discussion/9952/adding-parameters-through-fnserverparams-for-tabletools-ajax-calling/p1#Form_Comment
code

[code]"oTableTools": {
"aButtons" : [ {
"sExtends": "download",
"sButtonText": "Download CSV",
"sUrl": "/api/model/",
"sExtraData": [
{name: "bShowInactive", value: $("#bShowInactive").is(":checked")
]
} ]
}[/code]
function
[code]TableTools.BUTTONS.download = {
"sAction": "text",
"sTag": "default",
"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,
"sExtraData":[],
"fnClick": function( nButton, oConfig ) {
var oParams = this.s.dt.oApi._fnAjaxParameters( this.s.dt );
oParams = oParams.concat(oConfig.sExtraData);
console.log(oParams);
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 issue is that the div#bShowInactive doesnt exist before the datatables() function, so getting the is(:checked) returns null

div#bShowInactive is added after the datatables() completes, the sDOM includes <"showInactive"> and afterwards i run this

[code]
$("div.showInactive").html('Include inactive Events');
[/code]


any suggestions on how i can tie this all together

Replies

  • jrizzi1jrizzi1 Posts: 44Questions: 12Answers: 3
    edited June 2013
    Ok, the issue was the Tabletools Buttons function, i updated the oparams to push instead of concatenate and it worked fine
    [code]
    TableTools.BUTTONS.download = {
    "sAction": "text",
    "sTag": "default",
    "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,
    "sExtraData":[],
    "fnClick": function( nButton, oConfig ) {
    var oParams = this.s.dt.oApi._fnAjaxParameters( this.s.dt );
    oParams.push({name: "bShowInactive", value: $("#bShowInactive").is(":checked") });

    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]
This discussion has been closed.