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
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
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.
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
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"
);
});
}
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