Hi Have below import statements
import { loadScript } from "lightning/platformResourceLoader";
import JSPDF from '@salesforce/resourceUrl/jspdf';
import JSPDF_AUTO_TABLE from '@salesforce/resourceUrl/jspdfAutotable';
loading both the scripts in renderedCallback
renderedCallback() {
Promise.all([
loadScript(this, JSPDF, JSPDF_AUTO_TABLE)
.then(() => {
console.log('loaded');
this.jsPDFLoaded = true;
}).catch(() => {
console.log('not loaded');
})
]);
}
no error from the above code. jsPDF is working as expected but when I try the below code to create an auto table.
const { jsPDF } = window.jspdf;
const doc = new jsPDF({
encryption: {
userPermissions: ["print", "modify", "copy", "annot-forms", "download"]
}
});
doc.autoTable({
styles: { fillColor: [255, 0, 0] },
columnStyles: { 0: { halign: 'center', fillColor: [0, 255, 0] } }, // Cells in first column centered and green
margin: { top: 10 },
body: [
['Sweden', 'Japan', 'Canada'],
['Norway', 'China', 'USA'],
['Denmark', 'China', 'Mexico'],
],
})
it throws an error autoTable is not a function, could someone please suggest how to resolve this error?
JS-PDF library.
I am using this JS file for js-autoTable
UPDATE:
I have updated my renderedCallback as suggested in the answer below and it started working as expected but when I reload the page I am getting the same error now each time I click on edit to the static resource having jsPDFAutoTable and then reload the page it renders the autotable trust me I tried this 10 times before adding it here and this very strange not sure if this is a salesforce but or am I doing something wrong.