Kendo Grid 实时数据导出
对于我的一生,我无法确定解决方案。我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢 Tawab Wakil 找到了这个:
参考:Kendo Grid MVC /无需额外请求即可导出到 Excel
))
.ServerOperation(false) 就是这么做的
Thanks to Tawab Wakil for finding this:
Reference: Kendo Grid MVC / export to Excel without additional request
))
The .ServerOperation(false) is what did the trick