Problems with 1.8, mDataProp and TableTools exporting CSV, Excel...

Problems with 1.8, mDataProp and TableTools exporting CSV, Excel...

garrigarri Posts: 2Questions: 0Answers: 0
edited June 2011 in General
Hi.

We are working on a website using this great component.
We have a page with loads a table with JSON data from a Struts action
The structure of the JSON data is like this:

aaData: [
{
alarmas: {
idEquipoSupervisor: 286
}
idAlarma: 3801
idAlarmaActiva: 32
}
{
alarmas: {
idEquipoSupervisor: 317
}
idAlarma: 4249
idAlarmaActiva: 33
}
]


We have defined a table with the property for aoColumns making use of "mDataProp" faciilities, and it works fine.
We are using TableTools 1.8 beta3

Here is the definition:

alarmasActivasTable = $('#tabla').dataTable( {
"sAjaxSource": "alarmasActivas.action",
"sDom": 'rtpliT<"clear">',
"aoColumns": [
{"mDataProp": "idAlarmaActiva","sName":"idAlarmaActiva"},
{"mDataProp": "idAlarma","sName":"idAlarma"}],
"oTableTools": {
"sSwfPath": "${pageContext.request.contextPath}/media/swf/copy_cvs_xls_pdf.swf"
}
} );

It works fine, data is presented, and the table component works perfectly. But if we inject the component TableTools for exporting to CSV, Excel, PDF, we have a problem, since the result is a file with all data-rows 'undefined'.
Here is the result for the ClipBoard copy function, as an example
Id IdA
undefined undefined
undefined undefined
undefined undefined

We´ve discovered that if we dont define the aoColumns with "mDataProp", and specify it with fnServerData, it works perfectly.
This works for us

alarmasActivasTable = $('#tablaDetalleAlarmasActivas').dataTable( {
"sAjaxSource": "alarmasActivas.action",
"sDom": 'rtpliT<"clear">',
"fnServerData": fnServerObjectToArray (['idAlarmaActiva','idAlarma']),
"oTableTools": {
"sSwfPath": "${pageContext.request.contextPath}/media/swf/copy_cvs_xls_pdf.swf"
}
} );


However, this way we loose the facility of accessing for example the deeper properties in the JSON data, such as 'alarmas.idEquipoSupervisor' in the clean way that mDataProp gives. And that´s something we urgently need


Are we doing anything wrong?
Is there a solution for this?

Replies

  • garrigarri Posts: 2Questions: 0Answers: 0
    seems to be a problem in TableTools.js
    in the line 1414

    [code]var mTypeData = dt.aoData[ dt.aiDisplay[j] ]._aData[ i ];[/code]

    mTypeData is "undefined" for

    and it might be corrected by accesing aData array, but using the mDataProp value .

    am I right?
  • grudelsudgrudelsud Posts: 2Questions: 0Answers: 0
    hi guys,

    great tool, datatables is simply amazing but unfortunately I have exactly the same problem with tabletools, giving an undefined output.

    moreover, I cannot switch to sAjaxSource as the whole procedure is part of a larger function that does a lot of other stuff, so I need to access a json vector defined locally inside the scope.

    my code is:

    [code]var oTable = $('#datatable').dataTable({
    "bProcessing": true,
    "bLengthChange": false,
    "aaData": data.aaData,
    "aoColumns": [
    { "mDataProp": "date" },
    { "mDataProp": "total" },
    { "mDataProp": "english" },
    { "mDataProp": "italian" },
    { "mDataProp": "french" },
    { "mDataProp": "spanish" },
    { "mDataProp": "german" },
    { "mDataProp": "portuguese" },
    { "mDataProp": "other" }
    ],
    "sDom": 'Tlfrtip',
    "oTableTools": {
    "sSwfPath": assetsUrl + "/swf/copy_cvs_xls_pdf.swf",
    "aButtons": [ "copy", "csv" ]
    }
    });[/code]

    and my export gets out as:

    Date Tot EN IT FR ES DE PT Other
    undefined undefined undefined undefined undefined undefined undefined undefined undefined

    if someone could give me an idea to solve the problem, following garri's suggestion, I'd be happy to write some lines of codes

    many thanks
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Hi garri, grudelsud,

    Thanks very much for flagging this up - you are absolutely correct; TableTools needs to be updated for the mDataProp option in DataTables 1.8. I've just made and committed the required change which you can get from the "nightly" version on the downloads page: http://datatables.net/download/

    Regards,
    Allan
  • grudelsudgrudelsud Posts: 2Questions: 0Answers: 0
    hi allan

    you rock! it's working great now, thank you so much, I've also learned something reading your commit to github, for a better understanding of the library.

    just so you are aware, downloading the minimized version of the nightly build is giving an error:

    [code]Error occurred during initialization of VM
    Could not reserve enough space for object heap[/code]

    while the full version is working without problems

    thank you again, have a good w.e.
    thomas (aka grudelsud)
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Thanks for letting me know about that - something a bit weird going on on the server... Nightly is correct now though :-). Good to hear that fix does the job for you.

    Allan
  • chcltdchcltd Posts: 2Questions: 0Answers: 0
    I have upgraded to 1.8. The problem seems to have started since I implemented server side processing with filtering and paging (ie: each page makes an ajax request)

    Please see below output I am getting in a PDF - same for XLS. The print option does display the correct data.

    I have also enclosed the code I am using.

    Thanks in advance for help given.

    [quote]

    Your custom message would go here.
    Rendering engine Browser Platform(s) Engine version CSS grade
    undefined undefined undefined undefined undefined
    undefined undefined undefined undefined undefined
    undefined undefined undefined undefined undefined
    undefined undefined undefined undefined undefined
    undefined undefined undefined undefined undefined
    undefined undefined undefined undefined undefined
    undefined undefined undefined undefined undefined
    undefined undefined undefined undefined undefined
    undefined undefined undefined undefined undefined
    undefined undefined undefined undefined undefined

    [/quote]

    [code]

    $(document).ready(function() {
    var oTable = $('#example').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "bFilter": false, // do not have the search all columns in header
    "sAjaxSource": "/jqa/jqa_index/sources/dataTable/chcMySqlObjects.php",
    "aoColumns": [
    { "mDataProp": "products_quantity" },
    { "mDataProp": "products_image" },
    { "mDataProp": "products_price" },
    { "mDataProp": "products_date_available" },
    { "mDataProp": "products_date_end" }
    ],
    // "bJQueryUI": true, /* themeroller had problems with the full numbers layout */
    // "bStateSave": true, /* causes problems with column search as last state is remembered are not all values displayed */
    "sPaginationType": "full_numbers", /* page numbers */
    "sDom": 'T<"clear">lfrtip<"clear spacer">T', /* put print etc at top and bottom of table */
    "oTableTools": {"sSwfPath": "../jqa_plugins/jquery-dataTables/extras/TableTools/media/swf/copy_cvs_xls_pdf.swf",
    "aButtons": [{
    "sExtends": "collection",
    "sButtonText": "Print or Save",
    "aButtons": ["print",
    {
    "sExtends": "pdf",
    "sPdfOrientation": "landscape",
    "sPdfMessage": "Your custom message would go here."
    },
    "csv", "xls", "copy" ]}
    ]
    },
    "oLanguage": {
    "sSearch": "Search all columns:"
    },
    "fnDrawCallback": function () {
    $('#example tbody td').editable( '../examples_support/editable_ajax.php', {
    "callback": function( sValue, y ) {
    /* Redraw the table from the new data on the server */
    oTable.fnDraw();
    },
    "height": "14px"
    } );
    }
    } );
    $("tfoot input").keyup( function () {
    /* Filter on the column (the index) of this element */
    oTable.fnFilter( this.value, $("tfoot input").index(this) );
    } );
    $("tfoot input").focus( function () {
    if ( this.className == "search_init" )
    {
    this.className = "";
    this.value = "";
    }
    } );

    $("tfoot input").blur( function (i) {
    if ( this.value == "" )
    {
    this.className = "search_init";
    this.value = asInitVals[$("tfoot input").index(this)];
    }
    } );
    } );




    [/code]
  • chcltdchcltd Posts: 2Questions: 0Answers: 0
    Hi

    Just re-read post - I have installed 1.8.1

    Andy
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Have you also updated to the TableTools nightly?
  • mrowemrowe Posts: 1Questions: 0Answers: 0
    Hi,

    I have same problem and just updated both DT and TT.

    in case you want to see
    [code]
    oTable = $('#example').dataTable( {
    "sDom": 'T<"clear">lfrtip', //TABLETOOLS INIT
    "oTableTools": {
    "sSwfPath": "../assets/TableTools/media/swf/copy_cvs_xls_pdf.swf"
    },
    "bFilter": false,
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "../../api/index.php",
    "fnServerData": function ( sSource, aoData, fnCallback ) {

    /* Add some extra data*/
    aoData.push( { "name": "start_date", "value": $("#start_date").datepicker("getDate") } );
    aoData.push( { "name": "end_date", "value": $("#end_date").datepicker("getDate") } );
    aoData.push( { "name": "type", "value": "json" } );
    aoData.push( { "name": "class", "value": "order_system" } );
    aoData.push( { "name": "function", "value": "process_report" } );
    aoData.push( { "name": "sql", "value": sql } );
    $.getJSON( sSource, aoData, function (json) {
    fnCallback(json)
    } );
    },
    "aoColumns": [
    {
    "mDataProp": null,
    "sClass": "control center",
    "sDefaultContent": '+'
    },
    { "mDataProp": "member" },
    { "mDataProp": "total" },
    { "mDataProp": "percentage" }
    ]
    } );
    [/code]

    basically all data rows come back as "undefined" pdf or csv
  • wazzawazza Posts: 10Questions: 0Answers: 0
    Hi Allan, I'm experiencing the same problem with mDataProp and retrieving undefined data. Currently, I'm simply adding the tabletools plugin to default AJAX examples: "deep" and "objects".

    When including the nightly versions of Tabletools and Datatables, the output comprises of 0 rows, either for pdf, csv, xls or clipboard. As for the previous versions of the library, the output gets the correct number of rows, but each of their cells is "undefined".

    Best regards
  • TVGTVG Posts: 5Questions: 0Answers: 0
    I am having this problem as well.
  • TVGTVG Posts: 5Questions: 0Answers: 0
    Is this an issue with the latest build or are we doing something wrong?
  • JosJos Posts: 5Questions: 0Answers: 0
    I'm experiencing the exact same problem that wazza is describing:

    - Using mDataProp and serverside processing with objects.php
    - When using Datatables and Tabletools stable versions -> correct number of rows, but no data (all cells are "undefined")
    - When using Datatables and Tabletools nightly versions -> 0 rows

    Maybe important to mention: without using serverside processing all export options (clipboard, csv, Excel, pdf) are working fine.

    Any suggestions?
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    edited August 2011
    When reporting an issue, can you include a link to an example showing the problem please? I'm not currently able to reproduce this issue, so can't really help just now - hence a link would be very useful.

    With server-side processing and TableTools it will only export the visible rows (since it doesn't have access to all other rows on the client-side), but it should at least do that.

    Allan
  • JosJos Posts: 5Questions: 0Answers: 0
    edited August 2011
    A live example is difficult for me in my current work situation, but I've narrowed it down a bit further:

    - The following example code works (with aoColumns commented out), but only with the stable versions of DT and TT:

    [code]



    ID
    First Name
    Last Name
    Initials
    Email




    $(document).ready(function() {
    oTable = $('#example').dataTable({
    // Enable JQuery UI Theme support
    "bJQueryUI": true,
    // Enable state saving
    "bStateSave": true,
    // Set pagination type
    "sPaginationType": "full_numbers",
    // Set initial number of rows
    "iDisplayLength": 25,
    // Set default sorting column and direction (first column = 0)
    "aaSorting": [[ 2, "asc"]],
    // Enable column reordering and table tools
    "sDom": 'T<"clear"><"H"lfr>t<"F"ip>',
    // Setting the swf path for table tools
    "oTableTools": {
    "sSwfPath": "view/datatable/swf/copy_cvs_xls_pdf.swf"
    },
    // Enable server side processing
    "bProcessing": true,
    "bServerSide": true,
    // Set the data source
    "sAjaxSource": "view/datatable/scripts/server_processing.php",
    // Support column reordering and server side processing
    //"aoColumns": [
    // { "mDataProp": "user_id" },
    // { "mDataProp": "first_name" },
    // { "mDataProp": "last_name" },
    // { "mDataProp": "initials" },
    // { "mDataProp": "email" }
    //],
    // Language translations (NL)
    "oLanguage": {
    "sUrl": "view/datatable/datatable_nl.lang"
    },
    });
    } );

    [/code]

    - The nightly versions don't work with exactly the same example (0 rows copied to clipboard).

    When I uncomment the aoColumns part and change server_processing.php to objects.php, it stops working.
  • JosJos Posts: 5Questions: 0Answers: 0
    I forgot to mention:

    - My server_processing.php and objects.php are identical in configuration (same columns, user, password, db, server etc.).

    - Enabling ColReorder (adding R to the sDom) in the example above doesn't break the TT functionality.

    - Logical answer would be: why don't you just use server_processing.php? I can't use server_processing.php, because then sorting does not work correctly after using ColReorder.
  • JosJos Posts: 5Questions: 0Answers: 0
    Hi Allan and others,

    I'v solved the problem myself. The problem is in line 1414 of TableTools.js (2.0.1 stable version):
    [code]var mTypeData = dt.aoData[ dt.aiDisplay[j] ]._aData[ i ];[/code]

    When using aoColumns and mDataProp, this line should be:
    [code]var mTypeData = dt.aoData[ dt.aiDisplay[j] ]._aData[ dt.aoColumns[i].mDataProp ];[/code]

    This works, even for the serverside_processing.php example without aoColumns and mDataProp.

    I hope this will help!
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Thanks for the update! It should be noted that TableTools stable is not currently compatible with mDataProp in 1.8 (although your fix makes it work!). You would need the TableTools nightly to have it work with DataTabbles 1.8.x.

    Allan
  • JosJos Posts: 5Questions: 0Answers: 0
    In the nightly version, the preceding if-statement for selected rows (around line 1530 and further) was rewritten from if (...) { continue; } to if (...) { do stuff }, but the if statement is not entirely correct:
    [code]
    if ( (bSelectedOnly && $(dt.aoData[ dt.aiDisplay[j] ].nTr).hasClass( this.s.select.selectedClass )) ||
    (bSelectedOnly && this.s.select.selected.length == 0) )
    {
    [/code]

    I think this should be:
    [code]
    if ( (bSelectedOnly && $(dt.aoData[ dt.aiDisplay[j] ].nTr).hasClass( this.s.select.selectedClass )) ||
    this.s.select.selected.length == 0 )
    {
    [/code]

    This means something like:
    - When rows are selected, only take the selected rows
    - When no rows are selected, take everything
  • dvnandoverdvnandover Posts: 42Questions: 0Answers: 0
    All export worked except the print button. Does anyone see the same problem?
  • dvnandoverdvnandover Posts: 42Questions: 0Answers: 0
    For somereason the default setting of bShowAll set to true in the TablesTool.js file which caused my problem so i set bShowAll = false in the TablesTool initialization for the print button like this:
    {
    "sExtends": "print",
    "bShowAll: false
    }
    it worked fine now.
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Very odd! Can you link me to the page that you are using so I can see what is causing the error please?

    Thanks,
    Allan
  • logeloge Posts: 15Questions: 1Answers: 0
    Is there any way i can use TableTools with a column like that?

    { "mDataProp":null, "sTitle":"Date",
    "fnRender":function (oObj) {
    return oObj.aData.date.substring(0, 10);
    }
    },
    ...

    without fnRender, TableTools works well (of course only with nightly as discussed earlier)
This discussion has been closed.