Serialize dataTables variables

Serialize dataTables variables

TheDenominaterTheDenominater Posts: 6Questions: 0Answers: 0
edited August 2010 in General
Hi, I'm using the dataTables plugin (1.70) for jQuery (1.4.2) in my web application, and I'm trying to write a custom .csv export for my tables.

I've already got a fully functioning (search, pagination, filter, sort) dataTables set-up using server-side processing. What I'm trying to do is modify my php script that I use for server-side processing so that I can use it for my export.

I've successfully modified my php script to generate a csv file, except I can't figure out how to include the filtering, sorting, etc. My problems lies in the fact that when I call my php script, I am not including (by $_GET) all the special variables generated by dataTables for those purposes. (i.e. iSortingCols , sSearch , iColumns , ...). In my server-side implementation of datatable I assume the function call does that for me.

My question is therefore how would I go about getting all those variables so that I can serialize them into my _GET request?

I am currently calling the php script from jQuery as such:

[code]document.location.href = '/php_scripts/csv_export.php?query_name='+query_name;[/code]
Thank for any help, let me know if I should post more code.

The parameters I'm looking on are listed first on this page: http://datatables.net/usage/server-side

Replies

  • TheDenominaterTheDenominater Posts: 6Questions: 0Answers: 0
    So I managed to find a solution. I went into the dataTables file and sort of copied some of the code. Here's what I ended up doing.

    [code]
    getDataTableVars: function(oSettings){
    var iColumns = oSettings.aoColumns.length;
    var aoData = [];
    var i;

    /* General */
    aoData.push( { "name": "iColumns", "value": iColumns } );

    /* Filtering */
    if ( oSettings.oFeatures.bFilter !== false )
    {
    aoData.push( { "name": "sSearch", "value": oSettings.oPreviousSearch.sSearch } );
    for ( i=0 ; i
  • bikabika Posts: 25Questions: 0Answers: 0
    TheDenominater, many Thanks, I was looking for this.
    I added column visibility, copied a few other things from the latest DT release and wrapped it up in an API function

    Maybe Allan can include it in the api functions if this is helpful:

    [code]
    $.fn.dataTableExt.oApi.fnGetDataTableVars = function ( oSettings )
    {
    var iColumns = oSettings.aoColumns.length;
    var aoData = [];
    var i;

    /* Paging and general */
    oSettings.iDraw++;
    aoData.push( { "name": "sEcho", "value": oSettings.iDraw } );
    aoData.push( { "name": "iColumns", "value": iColumns } );
    aoData.push( { "name": "sColumns", "value": oSettings.oApi._fnColumnOrdering(oSettings) } );
    aoData.push( { "name": "iDisplayStart", "value": oSettings._iDisplayStart } );
    aoData.push( { "name": "iDisplayLength", "value": oSettings.oFeatures.bPaginate !== false ?
    oSettings._iDisplayLength : -1 } );

    /* Filtering */
    if ( oSettings.oFeatures.bFilter !== false )
    {
    aoData.push( { "name": "sSearch", "value": oSettings.oPreviousSearch.sSearch } );
    aoData.push( { "name": "bRegex", "value": oSettings.oPreviousSearch.bRegex } );
    for ( i=0 ; i
This discussion has been closed.