Reputation: 69
I would like to create a pdf of multiple selected rows within vue-tables-2. I have found a pdf library called pdfmake which looks great. Being new to this, I am struggling to see how I can:
this.checkedRows
for the tableData content. How do I get this into the pdf?I see how pdfmake has instructions to build out datatable content, but how can I make this work with vue-tables-2? pdfmake table content screenshot
If anyone knows a better pdf library for vue-tables-2 please let me know. Here is my code so far...
<v-server-table url="/removals" :data="tableData" :columns="columns" :options="options">
<input slot="selected" slot-scope="props" type="checkbox" :checked="props.row.selected" v-model="checkedRows" :value="props.row">
<button slot="afterFilter" type="submit" @click="createPDF">Create PDF</button>
</v-server-table>
My data content is just a very simple prototype right now:
data() {
return {
tableData: [],
checkedRows: [],
columns: [
'selected',
'sku',
],
options: {
}
}
And my method...
methods: {
createPDF() {
pdfMake.createPdf(docDefinition).download('PO.pdf');
}
}
Upvotes: 2
Views: 4095
Reputation: 1
you could install pdfmake
using the following command :
npm install pdfmake --save-dev
and import and use it as follow
<template>....</template>
<script>
var pdfMake = require('pdfmake/build/pdfmake.js');
var pdfFonts = require('pdfmake/build/vfs_fonts.js');
pdfMake.vfs = pdfFonts.pdfMake.vfs;
export default{
data() {
return {
tableData: [],
checkedRows: [],
columns: [
'selected',
'sku',
],
options: {
}
},
methods: {
createPDF() {
var docDefinition = {
content: [
{
table: {
headerRows: 1,
widths: [ '*', 'auto', 100, '*' ],
body: []
}
}
]
};
docDefinition.content[0].table.body.push(this.columns);
for(var i=0;i<this.checkedRows.length;i++){
docDefinition.content[0].table.body.push(Object.values(this.checkedRows[i]));
}
pdfMake.createPdf(docDefinition).download('PO.pdf');
}
}
}
Upvotes: 3