This is a migrated thread and some comments may be shown as answers.

PDF Export: Template with custom parameters has a problem with pageNum/totalPages

5 Answers 603 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Franz
Top achievements
Rank 1
Franz asked on 22 Nov 2016, 10:09 AM

Hi,

I'm exporting my KendoGrid to PDF with a Template. I need to pass variables to the template like this:

template: kendo.template($("#kendo-grid-pdf-template").html())({ CUSTOMERNAME: cust.FullName, CUSTOMERID: cust.Id})

 

This is the template:

<script id="kendo-grid-pdf-template" type="text/x-kendo-template">
    <div class="page-template-pdf">
        <div class="header-pdf">
            #: CUSTOMERNAME #, Customer ID: #: CUSTOMERID#
        </div>
    </div>
</script>

 

The Problem:

PDF generation fails because "pageNum" and "totalPages" are undefined. This only happens when I pass my custom parameters. How do I pass the pageNum and totalPages parameters that are required? It work when I pass it like this:

template: kendo.template($("#kendo-grid-pdf-template").html())({ CUSTOMERNAME: cust.FullName, CUSTOMERID: cust.Id, pageNum: "?", totalPages: "?"})

 

but where do I get the right values?

5 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 24 Nov 2016, 07:07 AM
Hello Franz,

Adding an additional data to the template is not supported as this will override the template context, that is why the pageNum is undefined as it is overwritten by the passed object.

Could you please provide more information about the scenario and a runnable example, so I can investigate and check if I can offer a different supported approach to achieve the desired result?

Thank you in advance.

Regards,
Stefan
Telerik by Progress
Kendo UI is ready for Visual Studio 2017 RC! Learn more.
0
Franz
Top achievements
Rank 1
answered on 24 Nov 2016, 08:16 AM

Hello Stefan,

One of my colleagues opened a ticket for this issue with additional code. The ticket ID is 1075891 if you want to check it out.

Thanks for your help.

0
Stefan
Telerik team
answered on 25 Nov 2016, 11:16 AM
Hello Franz,

I noticed that my colleague provided an answered to the ticket 1075891 and the ticket is marked as closed.

If additional information is needed on this matter, please let me know and I will gladly assist.

Regards,
Stefan
Telerik by Progress
Kendo UI is ready for Visual Studio 2017 RC! Learn more.
0
Franz
Top achievements
Rank 1
answered on 02 Dec 2016, 01:18 PM

Hello Stefan,

Today I noticed that my drawDOM function only generates 1 page in the PDF. I Need every page of the grid in my PDF Export.

I set "allPages: true", but to no avail. Can you please tell me what is wrong with my Approach?

window.exportPdf = function () {
 
            kendo.drawing.drawDOM("#leistungsanzeigeGrid",
            {
                multiPage: true,
                allPages: true,
                landscape: true,
                repeatHeaders: true,
                paperSize: ["500mm", "700mm"],
                margin: { top: "2.5cm", right: "0cm", bottom: "1cm", left: "0cm" },
                template: kendo.template($("#kendo-grid-pdf-template").html())(
                {
                    pageNum: "",
                    totalPages: "",
                    KDNR: person.Kundennummer,
                    NAME: person.DisplayFullName,
                    GEB: formatJsonDate(person.Geburtsdatum),
                    SEX: identifySex(person.Geschlecht),
                    SSN: person.DisplaySvnr
                })
            }).then(function (group) {
                kendo.drawing.pdf.saveAs(group, "test.pdf");
            });
        }

 

0
Stefan
Telerik team
answered on 06 Dec 2016, 08:20 AM
Hello Franz,

From the provided code I noticed that kendo.drawing.drawDOM used instead of the pdf property of the Grid. Please have in mind that kendo.drawing.drawDOM will export the DOM elements currently visible on the page.

The Grid has a built-in support for pdf export, please check the following demo demonstrating how to use the Grid pdf export:

http://demos.telerik.com/kendo-ui/grid/pdf-export

Also, please check all of the available options for PDF export available through the Grid' API:

http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-pdf 

Regards,
Stefan
Telerik by Progress
Kendo UI is ready for Visual Studio 2017 RC! Learn more.
Tags
Grid
Asked by
Franz
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Franz
Top achievements
Rank 1
Share this question
or