0

I am trying to hide one column from excelExport. I have tried some traditional ways shown on google like e.sender.hideColumn(13) or e.sender.hideColumn("bID") or grid.hideColumn(13). but none of this working for me. I have also done exportPDF which is working perfectly.

here is JS code I am attaching, to show what I am doing.

$("#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....
            },

.....

This is my js code. Can anyone guide where i am making mistake?

4

1 回答 1

1

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

对于此示例,事件被阻止并再触发一次,不包括隐藏列。

于 2018-01-25T15:04:09.543 回答