Kendo Grid 实时数据导出

发布于 2025-01-13 14:06:58 字数 5014 浏览 0 评论 0原文

对于我的一生,我无法确定解决方案。我有一个 Kendo Grid,可以抓取随机零件号进行审核。但是,当我将网格导出到 Excel 时,它会再次执行数据源,从而产生不同的零件号。

我想只导出屏幕上显示的内容,而不再次执行数据源。

我该怎么做?

这是代码的一个子集:

<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>

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. However, when I export the grid to Excel, it executes the datasource again, resulting in different part numbers.

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倥絔 2025-01-20 14:06:58

感谢 Tawab Wakil 找到了这个:

参考:Kendo Grid MVC /无需额外请求即可导出到 Excel

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

))

.ServerOperation(false) 就是这么做的

Thanks to Tawab Wakil for finding this:

Reference: 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文