Show hidden columns in Kendo grid excel export

前端 未结 3 522
清歌不尽
清歌不尽 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:07

    You can have columns in an array which defines hidden: true and then simply traverse through columns array and show/hide columns just before export as following:

            function excelExport(e) {
                  if (!exportFlag) {
                      for(var i=0; i < columns.length; i++) {
                          if(columns[i].hidden)
                              e.sender.showColumn(i);
                      }
                      e.preventDefault();
                      exportFlag = true;
                      setTimeout(function () {
                        e.sender.saveAsExcel();
                      });
                    } else {
                        for(var i=0; i < columns.length; i++) {
                              if(columns[i].hidden)
                                  e.sender.hideColumn(i);
                          }
                      exportFlag = false;
                    }
          }
    

提交回复
热议问题