Server Side Processing with export to csv

Server Side Processing with export to csv

satishpolasisatishpolasi Posts: 1Questions: 1Answers: 0

Hi,

I am using Server Side processing of DataTables. The project I am working on has huge volume of data multiple. I have some situations where the tables will be small, and I am going to do everything on the client side. This is the scenario where the tables will contain less than 100 rows. But, then I have the situation where I could be dealing with 1,000's of records and I want to allow the user to be able to specify filter's in the DataTables, but then export all of those filtered records out to a CSV.

By following these two links http://datatables.net/forums/discussion/5505/server-side-processing-with-export-to-csv-and-pdf and http://datatables.net/extensions/tabletools/plug-ins#download I am able to make a new seperate ajax call to get a whole resultset from server but at the end it does not downlaod the file to the client. Can you please let me know what I am missing in this. Below is my code. Thank you so much in advance.

$.fn.dataTable.TableTools.buttons.download = $.extend(
true,
{},
$.fn.dataTable.TableTools.buttonBase,
{
"sButtonText": "Download",
"sUrl": "",
"sType": "POST",
"fnData": false,
"fnClick": function( button, config ) {
var dt = new $.fn.dataTable.Api( this.s.dt );
var data = dt.ajax.params() || {};

                    // Optional static additional parameters
                    // data.customParameter = ...;

                    if ( config.fnData ) {
                        config.fnData( data );
                    }

                    var iframe = $('<iframe/>', {
                            id: "RemotingIFrame"
                        }).css( {
                            border: 'none',
                            width: 0,
                            height: 0
                        } )
                        .appendTo( 'body' );

                    var contentWindow = iframe[0].contentWindow;
                    contentWindow.document.open();
                    contentWindow.document.close();

                    var form = contentWindow.document.createElement( 'form' );
                    form.setAttribute( 'method', config.sType );
                    form.setAttribute( 'action', config.sUrl );

                    var input = contentWindow.document.createElement( 'input' );
                    input.name = 'json';
                    input.value = JSON.stringify( data );

                    form.appendChild( input );
                    contentWindow.document.body.appendChild( form );
                    form.submit();
                }
            }
        );

function initializeTable() {
var globalJson;

            var table = $('#eligibility-table').DataTable( {
                "bProcessing" : true,
                "bServerSide" : true,
                "bDeferRender": true,
                dom: "T<'clear'>BfrtiS",
                scroller: { displayBuffer: 4,
                            boundaryScale: .5,
                            tracer: true
                    },
                scrollY:       "510px", //set height of table
                scrollX:        true, // allow horizontal scrolling
                "orderClasses": false, // Always turn this off.  It highlights the sorted column.  Causes slowness.
                ScrollCollapse: true,
                ifixedColumns: {leftColumns: 2},
                "oTableTools": {
                    "sSwfPath": "../plugins/DataTables-1.10.3/extensions/TableTools/swf/copy_csv_xls_pdf.swf",
                    "aButtons": [
                      {
                        "sExtends": "download",
                        "sButtonText": "CSV",
                        "sButtonClass": "DTTT_button_csv",
                        "sButtonClassHover": "DTTT_button_csv_hover",
                        "sUrl": "../admin/generate_csv.php"
                      }]
                }

}

This discussion has been closed.