我试图从 excelExport 中隐藏一列。我尝试了谷歌上显示的一些传统方法,例如 e.sender.hideColumn(13)
或 e.sender.hideColumn("bID")
或 grid.hideColumn (13)
。但这些都不适合我。我还完成了 ExportPDF,效果非常好。
这是我附加的 JS 代码,以展示我在做什么。
$("#ALReport").kendoGrid({
toolbar: ["excel", "pdf"],
excel: {
allPages: true,
fileName: "ALReport" + todayDateFormatted() + ".xlsx",
proxyURL: "/content",
filterable: true
},
excelExport: function (e) {
e.sender.hideColumn(12);
var grid = $("#ALReport").data("kendoGrid");
grid.hideColumn("Bid");
},
pdf: {
allPages: true,
filterable: true,
fileName: "ALReport" + todayDateFormatted() + ".pdf",
proxyURL: "/content",
margin: {
left: 10,
right: "10pt",
top: "10mm",
bottom: "1in"
}
},
pdfExport: function (e) {
var grid = $("#ALReport").data("kendoGrid");
grid.hideColumn("Bid");
$(".k-grid-toolbar").hide();
e.promise
.done(function () {
grid.showColumn("Bid");
$(".k-grid-toolbar").show();
});
},
dataSource: {
serverSorting: true,
serverPaging: true,
transport: {
read: getActionURL() + "ALReport....
},
.....
这是我的js代码。谁能指导我哪里出错了?
最佳答案
导出到 Excel 没有任何效果,因为事件是在收集完所有数据后触发的。对于您的示例,请尝试以下方法:
var exportFlag = false;
$("#grid").kendoGrid({
toolbar: ["excel", "pdf"],
excel: {
allPages: true,
fileName: "ALReport" + todayDateFormatted() + ".xlsx",
proxyURL: "/content",
filterable: true
},
excelExport: function (e) {
if (!exportFlag) {
e.sender.hideColumn("Bid");
e.preventDefault();
exportFlag = true;
setTimeout(function () {
e.sender.saveAsExcel();
});
} else {
e.sender.showColumn("Bid");
exportFlag = false;
}
}
对于此示例,事件被阻止并再次触发,不包括隐藏列。
关于javascript - kendo Grid excelExport 的 hideColumn 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48445236/