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

dataKey not work in angular

Open mehrshadFarzaneh opened this issue 4 years ago • 2 comments

My PDF does not change when I use columnStyles with dataKey property, but my code works properly when I use the number instead of dataKey .

This is code that works incorrectly:

head = [{title: 'توضیحات', dataKey: 'MoreDescribe'},
{title: 'امکانات', dataKey: 'properties'},
{title: 'مبلغ خرید', dataKey: 'id'}]

body = [
[{content: ' قابل استفاده'},
{content: 'اندازه مناسب'},
{content: '10000 تومان'}],

[{content: ' قابل استفاده'},
{content: 'اندازه مناسب'},
{content: '10000 تومان'}],

[{content: ' قابل استفاده'},
{content: 'اندازه مناسب'},
{content: '10000 تومان'}]
]

printAll(){
const doc = new jsPDF();
autoTable(doc, {
      head: [this.head],
    body: this.body,
      headStyles: { font: 'Shabnam',halign: 'center',valign: "middle"}, // work
      bodyStyles: { font: 'Shabnam', halign: 'center', valign: "middle" }, // work

      columnStyles: {  id: { cellWidth: 5000 },properties:{cellWidth:700},MoreDescribe:{cellWidth:500} } // not work
    })
}

my result: image

if i change the columnStyles: { id: { cellWidth: 5000 },properties:{cellWidth:700},MoreDescribe:{cellWidth:500} } to columnStyles: { 1: { cellWidth: 5000 },2:{cellWidth:700},3:{cellWidth:500} } cellWidth style applies to my table. but I want to use dataKey. how can I do it?

mehrshadFarzaneh avatar Nov 11 '21 13:11 mehrshadFarzaneh

@mehrshadFarzaneh - I believe the issue is that you first need to declare the column information via the columns property in order to reference the keys in columnStyles:

columnStyles: {&columnDataKey: StyleDef} Note that the columnDataKey is normally the index of the column, but could also be the dataKey of a column if content initialized with the columns property

gs-scooter avatar Jan 05 '22 20:01 gs-scooter

@mehrshadFarzaneh - I believe the issue is that you first need to declare the column information via the columns property in order to reference the keys in columnStyles:

columnStyles: {&columnDataKey: StyleDef} Note that the columnDataKey is normally the index of the column, but could also be the dataKey of a column if content initialized with the columns property

I agree with what @gs-scooter has pointed out. columnStyles work by applying specific styles while referencing column by dataKey.

I think all you need to do is explicitly define which body column is id, properties and MoreDescribe. Then the styles will apply correctly.

iiminov avatar Jan 25 '22 09:01 iiminov