i need help to print pdf of my datatable with grouping.
i need help to print pdf of my datatable with grouping.
ziovik
Posts: 9Questions: 1Answers: 0
i have already added the _exportData = function ( dt, inOpts ) and my buttons. but it still get pdf without grouping.
my button
{
extend: 'collection',
text: 'Распечатать накладную ' + '<i style="color: green" class="glyphicon glyphicon-print"></i>',
'buttons': [
{
extend: 'print',
exportOptions: {
grouped_array_index: [0] //note the brackets, i think this is so you can group by multiple columns.
}
}
],
},
}
my table
var datatable = appCreateSimpleDataTable({
section: 'cat-awaitingDeliveryFilterInvoice',
columnSearch: true,
columns: columns_invoice_order,
select: {
style: 'os',
selector: 'td:first-child'
},
fields: form_invoice_order,
clearbtns: true,
buttons: buttons_invoice_order,
rowGroup: {
dataSrc: 'group'
},
dtOptions: {
select: {
style: 'os',
selector: 'td:first-child'
},
// "scrollY": "200px",
"order": [[0, "asc"]],
dom: 'Brtip',
"pageLength": 100,
'searchCols': [
null,
null,
],
'columnDefs': [
// {
// "render": (data, type, full) => {
// },
// "targets": [0]
// },
{ "name": "posting_number", "targets": 0 },
],
"processing": true,
"serverSide": true,
"paging": true,
"ajax": {
"url": "/cat-api-ozon/load_invoice",
"type": "POST",
"data" : {shipmentDate:shipmentDate, warehouseId:warehouseId},
// success: function(response) {
// console.log(response)
// },
// error: function(response) {
// console.log(response)
// }
},
'rowCallback': function(row, data, dataIndex){
$(row).css("cursor", "pointer");
},
"createdRow": function( row, data, index ) {
if(data.read_status === 0){
$('td', row).css('background-color', '#f2e5d0');
}
},
"drawCallback": function ( settings ) {
var api = this.api();
var rows = api.rows( {page:'current'} ).nodes();
var last=null;
api.column(0, {page:'current'} ).data().each( function ( group, i ) {
if ( last !== group ) {
$(rows).eq( i ).before(
// '<tr class="group"><td colspan="5">'+group+'</td></tr>'
'<tr class="group" style="height: 2px; background: grey"><td colspan="5"></td></tr>'
);
last = group;
}
} );
datatable.columns().eq(0).each( function (index ) {
var column = datatable.column( 0 );
var data = column.data();
for (let i = 0; i < data.length - 1; i++) {
if (data[i] === data[i + 1]) {
// console.log("We have a match!");
}else{
// console.log("We dont have a match!");
}
}
} );
}
},
beforeModalOpen: function () {
},
afterFillForm: function (data) {
}
});
but it still gives me pdf without grouping. i have tried all. i need help please
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
grouped_array_index
isn't a property I recognise - I'm not sure where that comes from and I don't see it referenced anywhere else in your code?I'm afraid that our export options to not currently support the RowGroup extension.
Allan
this is the button. where i want group to be in the first column. and the grouped_array_index is also in the function;
which i included in my dataTables.buttons.js.
the pdf group is not working. please help.
Did you write the code in there for the row grouping? It isn't written nor supported by us. You'd probably be best asking the original author if it wasn't yourself.
Allan
i am the author. Just tell me please what to do or show me what im doing wrong.
you mean i should remove this right:
rowGroup: {
dataSrc: 'group'
},
and what else im doing wrong.
if you are talking about the function of _exportData. i copied it from one of your link. if its wrong please tell me the right one and where and how to use it
I added lines 108-140 to the
dataTables.buttons.js
file in this example:http://live.datatables.net/bakokiva/1/edit
The code works for Print, PDF and Excel.
Please describe exactly what happens and what is not working.
Make sure you aren't also loading the unmodified
dataTables.buttons.js
. You only want to load this once. Maybe you need to clear the browser's cache to load the modified file. Make sure you are loading the files in the proper order.If you still need help then please provide a link to your page or a test case replicating the issue so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
https://datatables.net/forums/uploads/editor/5i/h6bgblhjc5b6.docx
i want something like this . not the way you group.
Sorry, I'm not sure what that screenshot is showing. It looks like a standard table to me. Is it grouped somehow?
Are you not using the rowGroup extension?
Please provide details of exactly what you are looking for.
Kevin
http://live.datatables.net/fecoqote/2/
this test lick. i want it to group like that but where the Ashton Cox for example shows twice it should merge that coloumn together only so the Ashton Cox shows once but other details should show. just to merge that two cells and show one of the Ashton Cox and leaves its other cells and row
https://datatables.net/forums/uploads/editor/zu/dvvv5myo7y5v.docx
please look at the first column and see the merged cells when the value are thesame
There is a third party plugin called rowsGroup that I think will group the rows the way you want. Note that this is a third party plugin and in not supported by Datatables. Any issue with it will need to go through the developer of the plugin. Also note that this plugin creates
rowspan
in thetbody
which is not supported by Datatables. See the HTML requirements for details.You can see an example from the fiddle in the first post in this thread.
Export functionality may or may not work with this plugin.
Kevin
ok lets try just merging cells. so how can i loop through a specific column and find if the values are thesame then merge cells?
To merge them you will need to create a
rowspan
in the table rows which is not supported by Datatables. The easiest way to do this is to use the third party rowsspan plugin as the code already does this. However you probably could add some code to thedrawCallback
function (I guess the second loop you have) to remove the duplicatetd
elements from the DOM and add the appropriaterowspan
to the firsttd
via jQuery.Either of these options probably won't be exported correctly so custom coding for the export buttons will need to happen if you want these custom groups exported.
Your best option is to use the Datatables RowGroup extension with the export solution posted above.
Kevin
I updated your test case to add the
rowspan
to merge duplicate cells.http://live.datatables.net/kozuwugu/1/edit
This is for the table display only. It won't apply to the export.
Since this adds a non-supported
rowspan
within the Datatables rows it may break some Datatables functionality. You will need to test this in your solution to make sure everything works as expected. If something is not working then this solution may not work for you and you will need to find something else.Kevin