TableTools download button plug-ins not working

TableTools download button plug-ins not working

RamprakashRamprakash Posts: 14Questions: 7Answers: 1

Hai all, I am using datatable for my sample application. I need to use TableTools extension for my application but my app won't support flash buttons so sSwfPath is useless for me. I found download button is the alternate option. When I tried to design my app following the examples the download button is not getting to my application rather warning is displyed.. It dispalys error alert as "TableTools: Warning - unknown button type: download"

Here are my code. Please tell where am I wrong..

/**
*
*/
var table;
var colIndex;
var sortingOrder;
var currentPage;

TableTools.BUTTONS.download = {
"sAction": "text",
"sTag": "default",
"sFieldBoundary": "",
"sFieldSeperator": "\t",
"sNewLine": "<br>",
"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 aoPost = [
{ "name": "hello", "value": "world" }
];
var aoGet = [];

        /* Create an IFrame to do the request */
        nIFrame = document.createElement('iframe');
        nIFrame.setAttribute( 'id', 'RemotingIFrame' );
        nIFrame.style.border='0px';
        nIFrame.style.width='0px';
        nIFrame.style.height='0px';

        document.body.appendChild( nIFrame );
        var nContentWindow = nIFrame.contentWindow;
        nContentWindow.document.open();
        nContentWindow.document.close();

        var nForm = nContentWindow.document.createElement( 'form' );
        nForm.setAttribute( 'method', 'post' );

        /* Add POST data */
        for ( var i=0 ; i<aoPost.length ; i++ )
        {
            nInput = nContentWindow.document.createElement( 'input' );
            nInput.setAttribute( 'name', aoPost[i].name );
            nInput.setAttribute( 'type', 'text' );
            nInput.value = aoPost[i].value;

            nForm.appendChild( nInput );
        }

        /* Add GET data to the URL */
        var sUrlAddition = '';
        for ( var i=0 ; i<aoGet.length ; i++ )
        {
            sUrlAddition += aoGet[i].name+'='+aoGet[i].value+'&';
        }

        nForm.setAttribute( 'action', oConfig.sUrl );

        /* Add the form and the iframe */
        nContentWindow.document.body.appendChild( nForm );

        /* Send the request */
        nForm.submit();
    },
    "fnSelect": null,
    "fnComplete": null,
    "fnInit": null
};

/* $(document).ready( function () {
$('#table').dataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"aButtons": [ {
"sExtends": "download",
"sButtonText": "Download XLS",
"sUrl": "../DataTableExample/FetchRows"
} ]
}
} );
} );*/

function submitData(){
alert('Method Called');
if (table){
table = $('#table').DataTable();
table.destroy();
}
else
{
colIndex=0;
sortingOrder='asc';
currentPage=0;
}
table=$('#table').dataTable({
"pagingType" : 'full_numbers',
"scrollY" : "200px",
"dom" : 'TRlfrCtip',
"order" : [colIndex,sortingOrder],
"displayStart": currentPage,
"colVis" : {
"activate" : "mouseover",
"restore" : "Restore"
},
"tableTools" : {
//"aButtons" : ["copy","csv","xls","pdf","print"],
"aButtons": [ {
"sExtends": "download",
"sButtonText": "CSV",
"sUrl": "../DataTableExample/FetchRows"
}]
//"sSwfPath": "http://cdn.datatables.net/tabletools/2.2.2/swf/copy_csv_xls_pdf.swf"
},
"ajax" : {
"url" : '../DataTableExample/FetchRows',
"dataType" : "json",
"type" : "POST",

    },
    "aoColumns" : [ {
        "mData" : "id",
        "sTitle" : "S. No"
    }, {
        "mData" : "name",
        "sTitle":"Name"
    }, {
        "mData" : "age",
        "sTitle":"Age"
    }, {
        "mData" : "designation",
        "sTitle":"Designation"
    }, {
        "mData" : "qualification",
        "sTitle": "Qualification"
    }, ],
    "deferRender": true
    //"columnDefs":[
    //{
    //  "targets" : colIndex,
    //  "visible" : false,
    //  "searchable" : true
    //}
    //]
});

$('#table tbody').on('click','tr',function(){

$(this).toggleClass('selected');

});

$(document).on('click','.sorting',function(){
//alert('Index plain:'+$(this).attr('data-column-index'));
colIndex=$(this).attr('data-column-index');
sortingOrder='asc';

});

$(document).on('click','.sorting_asc',function(){
//alert('Index asc:'+$(this).attr('data-column-index'));
colIndex=$(this).attr('data-column-index');
sortingOrder='asc';
setPage();

});
$(document).on('click','.sorting_desc',function(){
//alert('Index:'+$(this).attr('data-column-index'));
colIndex=$(this).attr('data-column-index');
sortingOrder='desc';
setPage();
});

setInterval( submitData, 20000 );

}

function setPage(){
$(document).find('#table_paginate').each(function(){
$(this).find('span a.current').each(function(){
currentPage=$(this).text();
alert('curretnPage:'+currentPage);
});
});

}

function hideThings(){
$('#table_length').css("display","none");
}

This discussion has been closed.