Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table header aligns always left #3028

Closed
mojtaba-khallash opened this issue Dec 9, 2020 · 3 comments · Fixed by #3032
Closed

Table header aligns always left #3028

mojtaba-khallash opened this issue Dec 9, 2020 · 3 comments · Fixed by #3032
Labels

Comments

@mojtaba-khallash
Copy link
Contributor

Executing the following code snippet in live demo is expected to create a table that all its rows including the header center align.

var headers = [
  {name: "id", align: "center", width: 100},
  {name: "name", align: "center", width: 100}
];

var data = [
  {id: "0", name: "Test 1"},
  {id: "1", name: "Test 2"}
];

var doc = new jsPDF({ orientation: "landscape" });
doc.table(1, 1, data, headers);

But contrary to expectations, the header has been left align!

image

The problem seems to be from the bottom line:

https://github.com/MrRio/jsPDF/blob/704f5a9bbf30421a81f2cf33803904e0db0227f1/src/modules/cell.js#L429

Should be use headers instead of headerNames

headerAligns = headers.map(function(header) {
@HackbrettXXX
Copy link
Collaborator

Thanks for the report. Your suggested fix seems reasonable. Could you prepare a PR?

@FastLogic1
Copy link

@mojtaba-khallash
if your are using autotable then use this line of code
headStyles: { halign: 'center'},

@mojtaba-khallash
Copy link
Contributor Author

I'm aware of this plugin, but generating the table in this way now meets my needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants