2

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:

  1. bring this into a vue-tables-2 component. Do I import this in the component?
  2. how would I create a pdf of multiple selected table row data? I have 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');
    }


}
0

1 Answer 1

3

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');
    }



    }
     }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.