在Kendo Grid Excel导出中显示隐藏的列 [英] Show hidden columns in Kendo grid excel export

查看:326
本文介绍了在Kendo Grid Excel导出中显示隐藏的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个剑道网格,可以毫无问题地将其数据导出到excel文件中.在我的网格中,某些列可能被隐藏,因为它们没有任何价值.但是,我甚至希望这些隐藏的列(我的意思是它们的标题)都在导出的excel文件中.

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 even these hidden columns (I mean their header) be in my exported excel file.

这是一段代码,显示了我的Kendo网格配置中的excel配置.

Here is a piece of code showing the excel config in my Kendo grid configuration.

excel: {
         fileName: new Date().toString() + ".xlsx",
         allPages: true,
       },

任何帮助将不胜感激.

推荐答案

您可以在定义了hidden的数组中包含列:true,然后只需在导出之前就遍历columns数组并显示/隐藏列即可:

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;
                }
      }

这篇关于在Kendo Grid Excel导出中显示隐藏的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆