jsPDF-AutoTable icon indicating copy to clipboard operation
jsPDF-AutoTable copied to clipboard

Uncaught TypeError

Open jdr430 opened this issue 11 years ago • 12 comments

Using google chrome I tried to run he script and recieved the following error pointing at line 12 of jspd.plugin.autotable.js Uncaught TypeError: Cannot read property 'events' of undefined. And because of this the autoTable function in unrecognised. How do I fix this?

jdr430 avatar Apr 17 '15 07:04 jdr430

Sounds strange, it would indicate that the API instance is not set. Could you post the code you are using?

simonbengtsson avatar Apr 17 '15 08:04 simonbengtsson

I tried using my own code but that didn't work so i'm just trying it with your example to see if it works. The code

$(document).on("click", "#PDF", function () {
      var columns = [
                     {title: "ID", key: "id"}, 
                     {title: "Name", key: "name"}, 
                     {title: "Country", key: "country"}, 
                     {title: "Email", key: "email"}
                 ];
                 var data = [
                     {"id": 1, "name": "Shaw", "country": "Tanzania", "email": "[email protected]"},
                     {"id": 2, "name": "Nelson", "country": "Kazakhstan", "email": "[email protected]"},
                     {"id": 3, "name": "Garcia", "country": "Madagascar", "email": "[email protected]"}

                 ];

                 var doc = new jsPDF('p', 'pt');
                 doc.autoTable(columns, data, {});
                 doc.save('table.pdf');
}); 

jdr430 avatar Apr 17 '15 08:04 jdr430

Strange! That code works for me. Check out this fiddle: https://jsfiddle.net/someatoms/buLugtcc/ Code you post the html as well?

simonbengtsson avatar Apr 17 '15 08:04 simonbengtsson

Can't seem to fix this error:

Uncaught TypeError: undefined is not a functionjspdf.plugin.autotable.js:39 defaultOptions.renderHeaderCelljspdf.plugin.autotable.js:233 (anonymous function)jspdf.plugin.autotable.js:230 printHeaderjspdf.plugin.autotable.js:88 API.autoTable(index):1204 (anonymous function)jquery-1.11.2.min.js:3 m.event.dispatchjquery-1.11.2.min.js:3 m.event.add.r.handle

On this line :

  y += settings.lineHeight / 2 + doc.internal.getLineHeight() / 2;

jdr430 avatar Apr 17 '15 09:04 jdr430

It seems to be a problem with your setup. Can you try to reproduce the issue in a jsfiddle or send me your entire html and js code?

simonbengtsson avatar Apr 17 '15 09:04 simonbengtsson

I can't create it on Fiddle, how do I send it to you?

jdr430 avatar Apr 17 '15 09:04 jdr430

Add it here.

simonbengtsson avatar Apr 17 '15 10:04 simonbengtsson

https://jsfiddle.net/jdr430/Lqgm0g77/

jdr430 avatar Apr 17 '15 10:04 jdr430

In the jsFiddle you need to include the jspdf before the autotable plugin, like in the jsfiddle I posted. I did the same error at first...

simonbengtsson avatar Apr 17 '15 10:04 simonbengtsson

Sorry about this I just realised the order was wrong. It now works fine I needed to place the debug before autotable. Thanks you can close this, sorry for time-wasting

jdr430 avatar Apr 17 '15 10:04 jdr430

No worries, let me know if run into other issues!

simonbengtsson avatar Apr 17 '15 10:04 simonbengtsson

Hi, I used following code and I am getting error EXCEPTION: Error in ./AppComponent class AppComponent - inline template:6:12 caused by: this.internal.getCurrentPageInfo is not a function

I tried following code , please suggest what I missed import { Component } from '@angular/core'; declare let jsPDF:any; @Component({ selector: 'my-app', template: <button (click)="trythis()">click</button> }) export class AppComponent{ cols:any=[ {headerName: "NAME", field: "name", width: 250}, {headerName: "AGE", field: "age", width: 250}, {headerName: "GENDER", field: "gender", width: 250} ]; rows:any=[ {name: "Geller", age: 30, gender: "Male"}, {name: "Geller", age: 28, gender: "Female"}, {name: "Tribbiani", age: 29, gender: "Male"}, {name: "Bing", age: 30, gender: "Male"}, {name: "Green", age: 28, gender: "Female"}, {name: "Buffay", age: 29, gender: "Female"} ]; trythis() { var doc = new jsPDF('p', 'pt'); doc.autoTable(this.cols, this.rows); doc.save("table.pdf") } }

snehalatapimprale avatar Mar 06 '17 09:03 snehalatapimprale