代码之家  ›  专栏  ›  技术社区  ›  Rush.2707

剑道网格excelExport的hideColumn不工作

  •  0
  • Rush.2707  · 技术社区  · 8 年前

    我试图对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代码。谁能告诉我哪里出错了?

    1 回复  |  直到 8 年前
        1
  •  1
  •   Przemysław Kleszcz    8 年前

    导出到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;
          }
        }
    

    在此示例中,事件被阻止并再次激发,不包括隐藏列。