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

Export PDF all pages not working

2 Answers 329 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jokull
Top achievements
Rank 1
Jokull asked on 07 Nov 2017, 02:13 PM

I am trying to export grid to PDF and I want it to export all pages. In my grid I have 2 pages but pdf only shows first page. In the grid dataSource I have set ServerOperation(true) and what happens is that the read action is called 3 times, first time the request is marked page 1, second time the request is marked page 2 and then the third time the request is marked page 1 again and therefore it only exports the first page.

Here's my grid:

@(Html.Kendo().Grid<MembersViewModel>()
.Name("participantsGrid")
.Columns(columns =>
{
columns.Bound(c => c.ID).Visible(false);
columns.Template(@<text></text>).ClientTemplate(@"<div class=''>"
+ "# if (HasAllergies) { # <i id='al-#=ID#' class=\"fa fa-exclamation-circle allergies\" data-tooltiptext='#=Allergies#' aria-hidden=\"true\"></i> # } #"
+ "</div>").Width(20).HtmlAttributes(new
{
style = "padding-left:5px;padding-right:5px"
});
columns.Bound(c => c.NAME).Title(translator.Translate("NAME"));
columns.Bound(c => c.SSN).Title(translator.Translate("SSN"));
columns.Bound(c => c.GENDER).Title(translator.Translate("GENDER"));
columns.Bound(c => c.AGE).Title(translator.Translate("AGE"));
columns.Template(@<text></text>).ClientTemplate(@"<div class='dropdown'>"
+ "<a data-toggle='dropdown' class='primarycolor' href=''><i class='fa fa-ellipsis-v fa-2x'></i></a>"
+ "<ul class='dropdown-menu dm-icon pull-right'>"
+ "<li><a class='k-button-icontext k-grid-edit' href='" + Url.Action("Edit", "Members") + "/#=ID#'>" + translator.Translate("EDIT") + "</a></li>"
+ "<li><a class='k-button-icontext' href='##'>" + translator.Translate("REGISTER_CLASS") + "</a></li>"
+ "</ul>"
+ "</div>").HtmlAttributes(new
{
@class = "dropdown-gridcell"
}).Width(20);
})
.ToolBar(toolbar =>
{
toolbar.Template(@<text>
<a class="k-button k-button-icontext k-grid-add" href="@Url.Action("", "")"><i class="fa fa-plus" aria-hidden="true"></i> @translator.Translate("ADD") @translator.Translate("PARTICIPANT_TGF")</a>
<a class="k-button k-button-icontext k-grid-excel" href="#"><span class="k-button-icontext k-i-excel"></span>Excel</a>
<a class="k-button k-button-icontext k-grid-pdf" href="#"><span class="k-icon k-i-pdf"></span>PDF</a>
</text>);
toolbar.Excel();
toolbar.Pdf();
})
.Pdf(pdf => pdf
.AllPages()
.AvoidLinks()
.PaperSize("A4")
.Scale(0.8)
.Margin("2cm", "1cm", "1cm", "1cm")
.Landscape()
.RepeatHeaders()
.TemplateId("page-template")
.FileName(string.Format("{0}_{1}.pdf", User.Identity.GetOrgName().Replace(' ', '_'), translator.Translate("PARTICIPANTS_PDFNAME")))
.ProxyURL(Url.Action("Pdf_Export_Save", "PDF"))
)
.Groupable(g => g.Messages(m => m.Empty(translator.Translate("DRAG_DROP_TO_ZONE_GROUPING"))))
.Sortable()
.Pageable()
.Filterable(filterable => filterable
.Extra(false)
.Messages(m => m.Clear(translator.Translate("CLEAR")).Filter(translator.Translate("FILTER")))
.Operators(operators => operators
.ForString(str => str.Clear()
.Contains(translator.Translate("CONTAINS"))
.StartsWith(translator.Translate("STARTS_WITH"))
)
)
)
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(2)
.ServerOperation(true)
.Read(read => read.Action("Participants_Read", "Participants").Data("additionalData"))
.Model(model => model.Id(mid => mid.ID))
.Create(update => update.Action("Participants_Create", "Participants"))
)
)

 

Here's my template:

<script type="x/kendo-template" id="page-template">
    <div class="page-template">
        <div class="header">
            <div style="float: right">Page #: pageNum # of #: totalPages #</div>
        </div>
        <div class="watermark">SAVI VEFKERFI</div>
        <div class="footer">
            Page #: pageNum # of #: totalPages #
        </div>
    </div>
</script>

And here's my controller action:

public ActionResult Participants_Read([DataSourceRequest] DataSourceRequest request, int? did, int? sdid, int? cid, int? sid)
{
    List<MembersViewModel> list = memberRepository.GetParticipantMembersList(this.saviSite.OrgId, did, sdid, cid, sid);

    return Json(list.ToDataSourceResult(request));
}

 

Can you tell me what I'm doing wrong here? Thanks!

2 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 09 Nov 2017, 07:21 AM
Hello, Jokull,

Thank you for the provided details.

Having three requests in this scenario is expected as the first two are for the exported Grid, and the last one is to load again the Grid current page. This can be observed in our demo as well:

http://demos.telerik.com/aspnet-mvc/grid/pdf-export

I noticed that in the ToolBar there are buttons for the PDF and Excel exports and then the built-in buttons are also used.

In general, the provided code looks good and should not cause the mentioned issue, could you please share a runnable example, so we can investigate what may be causing it?

Also, please advise if the used version is indeed 2017.3.1026 as we had a similar issue in one of the older versions of Kendo UI?

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Jokull
Top achievements
Rank 1
answered on 09 Nov 2017, 03:28 PM
Upgrading to 2017.3.1026 did the trick for me. Thanks!
Tags
Grid
Asked by
Jokull
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Jokull
Top achievements
Rank 1
Share this question
or