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

Edit a cell's borders one by one?

Open udvaritibor opened this issue 4 years ago • 8 comments

Hi! Is there a standard way to draw a horizontal line between the header and the body? Or a way to edit a cell so only its bottom border is drawn? Or a workaround is needed? Thanks!

udvaritibor avatar May 12 '20 13:05 udvaritibor

You currently need to draw a line yourself. If you want to do this I suggest doing so in the didDrawCell hook. That said this is a use case that would be great supporting better to more easily be able to draw more scientific looking tables such as the attached one.

Results-of-data-collection-on-scientific-paper

simonbengtsson avatar May 12 '20 18:05 simonbengtsson

Hello,

you can read this link https://stackoverflow.com/questions/58294682/jspdf-with-autotable-how-to-put-top-border-on-row-or-cells-in-row and modify the code in jspdf.plugin.autotable.js at 2023-2025 like indicated for adding a bottom border to a cell, use this in "DidParseCell" (after selecting th good cell) : HookData.cell.styles.borders = "b"; HookData.cell.styles.lineWidth = 0.1; "b" is for bottom

hope this can help you

BadApples11 avatar Aug 20 '20 07:08 BadApples11

HI, @BadApples11 ty for your insight! badly the link is dead, and HookData.cell.styles.borders = "b"; seems without no effect for me :/

ty in advance, Kevin

osterland avatar Aug 31 '20 19:08 osterland

Hi, I tried the link and it's dead. But the link doesn't go to the text (?) Copy the the text and not the link : https://stackoverflow.com/questions/58294682/jspdf-with-autotable-how-to-put-top-border-on-row-or-cells-in-row hope it would help you

BadApples11 avatar Sep 01 '20 05:09 BadApples11

I can help in this by providing some config in each cell so you can customise border width, colour and pattern i.e dashed for each direction separately

prpateldev avatar Oct 02 '20 09:10 prpateldev

@prpateldev What do you wating for?

edycarreyes99 avatar Aug 06 '21 16:08 edycarreyes99

@edycarreyes99 I have already made this feature and it's merged https://github.com/simonbengtsson/jsPDF-AutoTable/pull/730

prpateldev avatar Aug 07 '21 02:08 prpateldev

I found the following to be working using the didDrawCell hook.

autoTable(doc, {
  ... ,
  ... ,
  didDrawCell: function (data) {
    if (data.row.index === 0 && data.row.section === "body") {
      doc.setLineWidth(0.1);
      doc.line(4, 15, 56, 15); // the reuired x, y parameters
    }
   },
});

Also:

  1. A great example from the official repo

  2. Tested from Brave and Chrome

dhurjatichakraborty avatar Feb 01 '22 21:02 dhurjatichakraborty

Hii, Is there any way to remove the input field border in jsPDF

PathanMansoor avatar Jan 05 '23 07:01 PathanMansoor

  • You cn use didDrawCell

doc.autoTable({ didDrawCell: function(data) { // Modify the cell borders data.cell.styles.borderColor = '#0000FF'; data.cell.styles.borderWidth = 2; data.cell.styles.borderStyle = 'solid'; } });

mirajhad avatar Jan 05 '23 11:01 mirajhad

The support for controlling individual borders has been added some time ago. For example you could use this. For that to work, 'fillColor' needs to be passed as cell background. You can also experiment with lineWidth in the didParseCell hook

...
headStyles: {
      fillColor: 'white',
      lineWidth: {
        bottom: 1,
      },
      lineColor: 'red',
    },
...

@simonbengtsson I think this issue could be closed.

MikeDabrowski avatar Jul 14 '23 08:07 MikeDabrowski

True! 🎉🔥

simonbengtsson avatar Jul 14 '23 08:07 simonbengtsson