Export rowGroup to excel
Export rowGroup to excel
Lucaslopez12
Posts: 14Questions: 6Answers: 0
Hi.
I Have the following table and use rowGroup for quantities but when i want to export to excel it does not export the grouped data.
My code and example:
var TableServicios = $('#TableServicios').DataTable( {
responsive: false,
lengthChange: false,
"paging": false,
autoWidth: false,
searching: true,
fixedHeader: true,
"scrollX": true,
buttons: [{
extend: "excel",
title: '',
filename: 'Venta Servicios Adicionales',
exportOptions: { orthogonal: 'export' }
}],
language: {
"url": "//cdn.datatables.net/plug-ins/1.10.24/i18n/Spanish.json"
},
columns: [
{ "data": "Articulo" },
{
"data": "CantidadTotal", sType: "numeric"
},
{
"data": "Monto", sType: "numeric", render: function (data, type, row) {
return type === 'export' ?
data.replaceAll(/[$ |.]/g, '').replace(',', '.') :
data;
}
},
// ...allColumnsServices
],
rowsGroup: [0, 1, 2]
} );
I read that rowGroup is currently supported export options of the Buttons extension but i wanted to know if there is any solution for this today.
Thanks
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
This question has an accepted answers - jump to answer
Answers
You are using the rowsGroup plugin which is developed by a third party. I believe this is the link to the library:
https://github.com/ashl1/datatables-rowsgroup
This is different then the Datatables RowGroup extension. The rowsGroup plugin manipulates the HTML display directly and Datatables doesn't know about the changes. You can create a custom function to export the rows in the way you want. This thread shows an example of exporting the Datatables rowGroup. You will need to make some changes since you will need to group the rows before exporting them.
Kevin
Any example? I dont understand
Sorry there is not a specific example for what you want. I updated the example I linked to which simply exports all the rows:
http://live.datatables.net/fezituro/1/edit
It uses this statement to get all the rows:
It calls a blank function called
groupRows()
which still needs written. Currently it just returns the rowData passed into the functionThen it calls
updateSheet1()
to export the rowData rows to the excel sheet.All you should have to do is write the code for the
groupRows()
function to group the rows accordingly. There is nothing Datatables specific you will need in this function. Its just a Javascript exercise to loop through the original array passed in to build. new array with the grouped rows.Kevin