getting this error "Cannot read properties of undefined (reading 'table')" when set title= '' in
getting this error "Cannot read properties of undefined (reading 'table')" when set title= '' in
balaramLCS
Posts: 1Questions: 1Answers: 0
When I'm set title='' in pdfHtml5 export getting this error ERROR TypeError: Cannot read properties of undefined (reading 'table')
my code as following for PDF export
{
extend: "pdfHtml5",
title: '',
filename: function (){
$(".export-txt2").on('change', function() {
return $("#repHdr1").val() + '\n' + $("#repHdr2").val();
// return "filename"
})
return $("#repHdr1").val() + '\n' + $("#repHdr2").val();
// return "change filename";
},
className: "btn btn-primary",
orientation: 'landscape',
pageSize: 'A4',
exportOptions: {
columns: ':visible',
search: 'applied',
order: 'applied',
},
customize: (doc) => {
doc.layout = 'lightHorizotalLines'
// doc.content[1].table.widths = Array(doc.content[1].table.body[0].length + 1).join('*').split('');
let colCount = $("#datatable tr th").length;
let width = [];
let percentage = 100 / colCount;
for (let index = 0; index < colCount; index++) {
width.push((percentage) + "%");
}
doc.content[1].table.widths = width;
doc.defaultStyle.alignment = 'center';
doc.styles.tableHeader.alignment = 'center';
//pageMargins [left, top, right, bottom]
//----------------------
doc.pageMargins = [10, 25, 10, 25];
// doc.pageMargins = [10, 20, 10, 20];
var now = new Date();
var jsDate = now.getDate() + '-' + (now.getMonth() + 1) + '-' + now.getFullYear();
// Set the font size fot the entire document
doc.defaultStyle.fontSize = 10;
// console.log("pdf style: ", doc)
// Set the fontsize for the table header
doc.styles.tableHeader.fontSize = 12;
doc.styles.title.fontSize = 12;
//----------------------
this.hedAllPage ? doc['header'] = (function (page, pages) {
return {
columns: [
{
alignment: 'center',
text: page == 1? "heder\ntitle" : $("#repHdr1").val() + '\n' + $("#repHdr2").val(),
fontSize: page == 10? 0 : 10,
}
],
margin: page == 1? [10,0,10,0] : [10,0,10,0],
}
}): "";
doc['footer'] = (function (page, pages) {
return {
columns: [
{
alignment: 'left',
text: ['Created on: ', { text: jsDate.toString() }]
},
{
alignment: 'right',
text: ['page ', { text: page.toString() }, ' of ', { text: pages.toString() }]
}
],
margin: 10,
}
});
},
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Good evening, I have a similar error when I want to export to PDF, I use datatable 5
Uncaught TypeError: Cannot read properties of undefined (reading 'records')
function Load_Tabla_Orden() {
var exportColumns = [0, 1, 2, 3, 4, 5, 6, 7, 8];
}
As Colin stated, please link to a test case showing the issue so we can debug it.
Does it work if you remove your
customize
function?Allan