如何解决文件名的 ASP.NET MVC Kendo UI Excel 网格数据
我有一个可以显示所有产品的网格,但我们有按钮来决定在网格中显示哪些产品,例如“帽子”、“棒球”或“鞋子”。
选择按钮时,Ajax 调用让我的 jQuery 处理 onDataBound
事件以正确过滤数据,Excel 会提取所有数据,而不仅仅是 PageSize 设置中显示的数字。
但是,所有报告都称为“Report.xlsx”,我想使用产品自定义它们,例如“CapsReport.xlsx”或“BaseballsReport.xlsx”。
如何将此值发送到下面的 FileName("Report.xlsx")
?
<script>
function onButtonClick() {
$(this).addClass('active').sublings().removeClass('active');
var value = $(this).val() + 'Report.xlsx'; // this is the value I want to send to the Excel Filename
@(Html.Kendo().Grid<Model>().Excel.FileName(value)) // this line is obviously wrong
}
</script>
<div id="ReadTypeBtnGroup" class="btn-group">
<button type="button" id="caps" value="Caps" class="btn btn-default">Caps</button>
<button type="button" id="baseballs" value="Baseballs" class="btn btn-default">Baseballs</button>
<button type="button" id="shoes" value="Shoes" class="btn btn-default">Shoes</button>
</div>
<div class="panel-body">
@(Html.Kendo().Grid<Model>()
.AutoBind(false)
.DataSource(o => o
.Ajax()
.Read(o2 => o2.Action("GetReport","Report"))
.PageSize(20)
.ServerOperation(true)
)
.Events(o => o.DataBound("onDataBound"))
.Excel(o => {
o.AllPages(true);
o.Collapsible(true);
o.FileName("Report.xlsx");
})
.Name("grid")
.Pageable()
.ToolBar(o => {
o.Excel();
})
)
</div>
解决方法
向 excelExport 事件添加一个事件处理程序,像这样 .Events(e => e.ExcelExport("excelExport"))
您可以在那里更改文件的名称以及其他属性。
例如:
function excelExport(e) {
e.workbook.fileName = $("#someFieldHoldingFileName").val();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。