【问题标题】:Kendo Grid Excel Export with Columns with DropDown TemplateKendo Grid Excel 导出,带有下拉模板的列
【发布时间】:2015-05-22 09:32:27
【问题描述】:

我想将剑道网格数据导出到 excel 中。我正在使用剑道下拉列表作为某些列的模板。

当我导出它时,它会导出,但它不显示这些列的文本值,而是显示该字段的值。

【问题讨论】:

    标签: excel templates kendo-grid export-to-excel


    【解决方案1】:

    这可能不是“最佳”解决方案,但它对我有用。基本上,我创建了一个函数,该函数循环并处理带有下拉列表的行,使用 switch 语句根据值设置文本(不幸的是,通过的数据只有值,而不是对象)。

    这是我的网格的标记:

    <div id="grid" data-role="grid"
    data-sortable=" {mode: 'single' , allowunsort:true }"
    data-toolbar="[{template: this.model.getToolbar}]"
    data-excel="{ fileName: 'export.xlsx', allPages:'true' }"
    data-excel-export="model.curateExcelData"
    data-columns="@string.Format(@"[
            {{ title:'{0}', field: 'Column1', width:80 }},
            {{ title:'{1}', field: 'Column2', width:80 }},
            {{ title:'{12}', field: 'DropDownColumn',template: kendo.template($('#dropdown-template').html()),'width':80, sortable: false }},
    ]", CommonResource.Column1, CommonResource.Column2, CommonResource.DropDownColumn)"
    data-bind="source: items"
    data-editable="inline">
    </div>
    

    还有模板:

    <script id="dropdown-template" type="text/x-kendo-template">    
        <input data-role="dropdownlist"
               data-auto-bind="false"
               data-value-primitive="true"
               data-text-field="Text"
               data-value-field="Value"
               data-bind="value: dropDownValue, source: dropDownValues"
               style="width:65px" />
    </script>
    

    这里是更新导出值的函数(在我的例子中,我有一个下拉菜单,即“天”和“周”,这是第 12 列):

    curateExcelData: function (data) {
                var sheet = data.workbook.sheets[0];
                $.each(sheet.rows, function (index, row) {
                    if (row.type == "data") {
                        switch (row.cells[12].value) {
                            case "D":
                                row.cells[12].value = "Days";
                                break;
                            case "W":
                                row.cells[12].value = "Weeks";
                            default:
                                break;
                        }
                    }
                });
            },
    

    【讨论】:

      猜你喜欢
      • 2021-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多