Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 剑道网格导出为Excel下拉列表值,而不是导出文件中的文本_Javascript_Asp.net Mvc_Kendo Ui_Kendo Grid_Export To Excel - Fatal编程技术网

Javascript 剑道网格导出为Excel下拉列表值,而不是导出文件中的文本

Javascript 剑道网格导出为Excel下拉列表值,而不是导出文件中的文本,javascript,asp.net-mvc,kendo-ui,kendo-grid,export-to-excel,Javascript,Asp.net Mvc,Kendo Ui,Kendo Grid,Export To Excel,当我使用saveAsExcel导出网格时,下拉列表中的列显示的是值(GUID),而不是文本。 如何在导出的文件中显示文本而不是值?您可以将处理程序绑定到网格的“excelExport”事件,该事件在导出之前触发,并允许您首先调整数据。您可以在行和列之间循环,以在columns values集合中将id值替换为其映射。这是蛮力,但有效。另一种更有效的方法是在服务器上创建excel文件,而不是网格提供的客户端处理,它使用直接提供文本值的优化查询 这是我们使用的函数。它适用于所有外键列,而不仅仅是枚举

当我使用saveAsExcel导出网格时,下拉列表中的列显示的是值(GUID),而不是文本。
如何在导出的文件中显示文本而不是值?

您可以将处理程序绑定到网格的“excelExport”事件,该事件在导出之前触发,并允许您首先调整数据。您可以在行和列之间循环,以在columns values集合中将id值替换为其映射。这是蛮力,但有效。另一种更有效的方法是在服务器上创建excel文件,而不是网格提供的客户端处理,它使用直接提供文本值的优化查询

这是我们使用的函数。它适用于所有外键列,而不仅仅是枚举(尽管名称不同)

var replaceEnums = function (e) {

    //Purpose:
    //  Convert enumeration columns to use the string value.

    var hiddenCnt = 0;
    var groupCnt = 0;
    var dataCnt = false;

    //Loop through the columns and look for a values collection. 
    for (var iCol = 0; iCol < e.sender.columns.length; iCol++) {
        //if the column is hidden then do not do the replacement
        if (!e.sender.columns[iCol].hidden) {
            //If the values collection exists that means the column is an enumeration.
            if (e.sender.columns[iCol].values) {
                //Loop through each row
                for (var iRow = 1; iRow < e.workbook.sheets[0].rows.length; iRow++) {
                    if (e.workbook.sheets[0].rows[iRow].type == "data") {
                        var cell = e.workbook.sheets[0].rows[iRow].cells[iCol - hiddenCnt + groupCnt]
                        dataCnt = true;
                        //Loop through the enumeration and get the string value.  Stop once the correct
                        //value is found.
                        for (var iEnums = 0; iEnums < e.sender.columns[iCol].values.length; iEnums++) {
                            if (e.sender.columns[iCol].values[iEnums].value == cell.value) {
                                //Replace the enum value with the string value.
                                cell.value = e.sender.columns[iCol].values[iEnums].text
                                break
                            }
                        }
                    }
                    else {
                        //Track the number of group headers.  We need to track the 
                        //number of group headers because a group causes the columns
                        //to shift over by one for each grouping.
                        if (e.workbook.sheets[0].rows[iRow].type == "group-header") {
                            if (!dataCnt) {
                                groupCnt++;
                            }

                        }
                    }
                }
            }
        }
        else {
            //The column is hidden so add it to the count of hidden columns
            hiddenCnt++;
        }
    }
};

grid.bind("excelExport", replaceEnums);
var replaceEnums=函数(e){
//目的:
//转换枚举列以使用字符串值。
var-hiddenCnt=0;
var-groupCnt=0;
var-dataCnt=false;
//循环遍历列并查找值集合。
for(var iCol=0;iCol
在我的例子中,我有远程数据源的下拉列表,当我为下拉列表导出主网格时,数据不可用,因此它只显示guid。您必须以某种方式获取guid文本映射。您可以在事件开始时获取它们,并使用它们而不是columns.values。可能还有其他一些可能性,但除非您发布带有示例数据的dojo/jsbin,否则我无法探索它们。谢谢,在您的代码的帮助下,我想出了一个解决方案,它成功了!