Export current state of datatable

Export current state of datatable

jbadjbad Posts: 4Questions: 0Answers: 0
edited October 2009 in General
I've looked over the plugins and documentation (and read alot of forum posts) and haven't seen anything on this yet. What I'd like to do is export the current state of the grid (filtered, sorted, searched - whatever ends up being available, hidden columns included) into JSON or something that could be sent and parsed server side. The TableTools plugin exports, so it should contain most of the logic needed - but is that the best starting point? Is there a function I'm overlooking on the base DataTables?

BTW - incredibly nice work on this. By far the best datagrid plugin I've seen to date.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi jbad,

    Thanks for the kind words about DataTables! There isn't a built-in method or plug-in currently available which will do exactly what you are looking for. As you say, TableTools could be altered to do it, but that seems like overkill to me. You basically want fnGetData() which will take account of sorting etc, so try something like this:

    [code]
    /*
    * Function: fnGetDisplayData
    * Purpose: Return an array with the data arrays used for displaying the table
    * Returns: array node: data array elements
    * Inputs: object:oSettings - automatically added by DataTables
    */
    $.fn.dataTableExt.oApi.fnGetDisplayNodes = function ( oSettings )
    {
    var aaData = [];
    for ( var j=0, jLen=oSettings.aiDisplay.length ; j
This discussion has been closed.