How to exclude columns during export

2 posts, 1 answers
  1. J
    J avatar
    6 posts
    Member since:
    Apr 2017

    Posted 18 Sep Link to this post

    Hello,

    I'm using this code in my grid:

     

       .ToolBar(tools => tools.Excel())
         .Excel(excel => excel
            .FileName("Ci_view.xlsx")
            .Filterable(true)
            .ProxyURL(Url.Action("ExportExcelSave", "Ci"))
            .AllPages(true)

    My question is; how can I exclude some columns from my Excel?

     

    Thanks!!

     

  2. Answer
    Georgi
    Admin
    Georgi avatar
    156 posts

    Posted 21 Sep Link to this post

    Hi,

    Possible solution is to hide the columns you want to exclude when the excelExport event is fired. The following code block illustrates how to hide a column before the export and then show it back after the export is done:

    var exportFlag = false;
    $("#grid").data("kendoGrid").bind("excelExport", function (e) {
        if (!exportFlag) {
            e.sender.hideColumn(1); // index of the column you want to exclude
            e.preventDefault();
            exportFlag = true;
            setTimeout(function () {
                e.sender.saveAsExcel();
            });
        } else {
            e.sender.showColumn(1);
            exportFlag = false;
        }
    });
     
    Please give it a try and let me know if it works for you.


    Regards,
    Georgi
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top