简体   繁体   English

实时数据的剑道网格导出

[英]Kendo Grid Exporting of Live Data

For the life of me, I cannot determine a solution to this.对于我的生活,我无法确定解决方案。 I have a Kendo Grid that grabs random part numbers for an audit.我有一个 Kendo Grid,可以随机获取部件号进行审核。 However, when I export the grid to Excel, it executes the datasource again, resulting in different part numbers.但是,当我将网格导出到 Excel 时,它再次执行数据源,导致不同的零件号。

I would like to just export what is displayed on the screen and not execute the datasource again.我只想导出屏幕上显示的内容,而不是再次执行数据源。

How do I do this?我该怎么做呢?

Here is a subset of the code:这是代码的一个子集:

<section class="panel">
        @(Html.Kendo().Grid<DTO.GenerateRandomPartNumsList>()
                .Name("RandomNumberGeneratorGrid")
                .Columns(columns => {
                    columns.Bound(p => p.VendorName).ClientTemplate("<div class='cell-with-copy'><div>#:VendorName #</div><i class='fas fa=clipboard icon-copy'></i></div>")
                    .HtmlAttributes(new { @class = "k-hover" }).Width(125);
                    columns.Bound(p => p.PartNo).ClientTemplate("<div class='cell-with-copy'><div>#:PartNo #</div><i class='fas fa=clipboard icon-copy'></i></div>")
                    .HtmlAttributes(new { @class = "k-hover" }).Width(125);
                    columns.Bound(p => p.OnHand).ClientTemplate("<div class='cell-with-copy'><div>#:OnHand #</div><i class='fas fa=clipboard icon-copy'></i></div>")
                    .HtmlAttributes(new { @class = "k-hover" }).Width(125);
                    columns.Bound(p => p.PartDesc).ClientTemplate("<div class='cell-with-copy'><div>#:PartDesc #</div><i class='fas fa=clipboard icon-copy'></i></div>")
                    .HtmlAttributes(new { @class = "k-hover" }).Width(125);
                    columns.Bound(p => p.Bin).ClientTemplate("<div class='cell-with-copy'><div>#:Bin #</div><i class='fas fa=clipboard icon-copy'></i></div>")
                    .HtmlAttributes(new { @class = "k-hover" }).Width(125);
                    columns.Bound(p => p.PackageQuantity).ClientTemplate("<div class='cell-with-copy'><div>#:PackageQuantity #</div><i class='fas fa=clipboard icon-copy'></i></div>")
                    .HtmlAttributes(new { @class = "k-hover" }).Width(125);
                    columns.Bound(p => p.Cost).ClientTemplate("<div class='cell-with-copy float-right'><div>#:Cost #</div><i class='fas fa=clipboard icon-copy'></i></div>")
                    .HtmlAttributes(new { @class = "k-hover" }).Width(125);
                    columns.Bound(p => p.TotalValue).ClientTemplate("<div class='cell-with-copy float-right'><div>#:TotalValue #</div><i class='fas fa=clipboard icon-copy'></i></div>")
                    .HtmlAttributes(new { @class = "k-hover" }).Width(125);
                })
                .Pageable(pager => pager.AlwaysVisible(true).PageSizes(new int[] {minRecords,
                                        (minRecords * 2),
                                        (minRecords * 3),
                                        (minRecords * 4)}))
                .Sortable()
                .Resizable(resize => resize.Columns(true))
                .Selectable(selectable => selectable
                .Mode(GridSelectionMode.Single)
                .Type(GridSelectionType.Cell))
                .Navigatable()
                .Events(ev => ev.Change("copyCell"))
                .AllowCopy(true)
                .Scrollable()
                //.Filterable()
                .ToolBar(toolbar => {
                    toolbar.ClientTemplateId("RandomNumberGeneratorToolBar");
                })
                .Excel(excel=>excel
                    .FileName("RandomPartNumbers.xlsx")
                    .AllPages()
                    .ProxyURL(Url.Action("Excel_Export_Save", "RandomPartNumbers"))
                )
                .Pdf(pdf => pdf
                                .AllPages()
                                .AvoidLinks()
                                .PaperSize("A4")
                                .Margin("2cm", "1cm", "1cm", "1cm")
                                .RepeatHeaders()
                                .Landscape()
                                .Scale(.5)
                                .TemplateId("page-template")
                                .FileName("RandomPartNums.pdf")
                                .ProxyURL(Url.Action("Pdf_Export_Save", "RandomPartNums"))
                            )
                .Search(search =>
                {
                    search.Field(f => f.VendorName)
                    .Field(f => f.PartNo)
                    .Field(f => f.PartDesc)
                    .Field(f => f.Bin);
                })
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .PageSize(minRecords)
                    .Read(read => read.Action("ReadRandomPartsNumbers", "Parts")
                    .Data("getFilterData"))
                )
                .LoaderType(Kendo.Mvc.UI.GridLoaderType.LoadingPanel)
            )
    </section>

Thanks to Tawab Wakil for finding this:感谢 Tawab Wakil 发现这个:

Reference: Kendo Grid MVC / export to Excel without additional request参考: Kendo Grid MVC / export to Excel without additional request

.DataSource(ds => ds
.Ajax()
.PageSize(30)
.Read(r => r.Action("GetTaskItems", "Home")
.Type(HttpVerbs.Get))
.ServerOperation(false)

)) ))

The.ServerOperation(false) is what did the trick The.ServerOperation(false) 是什么把戏

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM