Show hidden columns in Kendo grid excel export

前端 未结 3 520
清歌不尽
清歌不尽 2021-01-19 19:19

I have a kendo grid and I can export its data into excel file without any problem. In my grid, some columns may be hidden because they do not have any value. However, I want

3条回答
  •  囚心锁ツ
    2021-01-19 20:04

    You can add some javascript to control this.

    var exportFlag = true;
    
    $("#gridName").data("kendoGrid").bind("excelExport", function (e) {
        if (exportFlag) {
            e.sender.showColumn("hiddenColumnName");
            e.preventDefault();
            exportFlag = false;
            e.sender.saveAsExcel();
        } else {
            e.sender.hideColumn("hiddenColumnName");
            exportFlag = true;
        }
    });
    

    Basically this catches the excelExport event when you click the Export button and shows the hidden column in your grid before it fires the saveAsExcel() function which saves your document. Then it hides the column again.

    Here is an Example you can test with.

提交回复
热议问题