Problems with 1.8, mDataProp and TableTools exporting CSV, Excel...
Problems with 1.8, mDataProp and TableTools exporting CSV, Excel...
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?
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?
This discussion has been closed.
Replies
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?
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
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
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)
Allan
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]
Just re-read post - I have installed 1.8.1
Andy
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
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
- 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?
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
- 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.
- 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.
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!
Allan
[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
{
"sExtends": "print",
"bShowAll: false
}
it worked fine now.
Thanks,
Allan
{ "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)