Open joadr opened 7 years ago
For now, you can achieve your goal with something like this. I use this method to draw images, for example:
table.setColumns([
{
id: 'code',
header: 'Code',
width: 35,
height: 18,
valign: 'center',
cache: false, // so you can draw your image
renderer: function (tb, data, draw, column, pos) {
if (draw) { // at first call: false. Then it's true
if (!data.barcode) {
return 'No barcode (' + data.id + ')';
}
tb.pdf.image(data.barcode, pos.x, pos.y, {
width: column.width,
height: column.height
});
}
return ''; // you need to return a string
}
}
]);
Basically, the lib makes 2 calls of the renderer. The first time to calculate the content height, the second time to draw it. Here, we set a fixed height and return an empty string first, and then we draw the image at the second call (and still return an empty string).
Should this does the trick for you?
Hmm can you give an example for that? Can't get it working. Tried this but 'pos' is undefinied:
.addColumns([
{
id: 'beschreibung',
header: 'Beschreibung',
align: 'left'
},
{
id: 'zeitraum',
header: 'Zeitraum',
width: 100,
cache: false,
renderer: function (tb, data, draw, column, pos) {
tb.pdf.font('Helvetica-Bold').text('A movie about dreams', pos.x, pos.y).font('Helvetica');
return '';
}
},
@helgetan the renderer is called twice. The first time, pos
has no value, because nothing is being drawn on the page. When draw
is true, it means it's time to draw something on the page. At this moment, pos
should have a value. Try this:
renderer: function (tb, data, draw, column, pos) {
if (draw) {
tb.pdf.font('Helvetica-Bold').text('A movie about dreams', pos.x, pos.y).font('Helvetica');
}
return '';
}
In my project I need to add some data in the tables with different styling, reviewing your code I found out that it should be possible by changing this part of the code:
that's right here: https://github.com/voilab/voilab-pdf-table/blob/master/voilab-table.js#L95
This way, this will just add text... but... what do you think about replacing that with:
This way I can put a function with my own styling, or even put images or anything inside the cell like this:
in theory that should work.... what do you think?