javascript - 导出 Kendo Grid 时 footerTemplate 显示 html 字符串?

标签 javascript html kendo-ui kendo-grid

我有带有 footerTemplate 的剑道网格。我已成功将此网格导出为 Excel。但导出的 Excel footerTemplate 显示 html 字符串。

示例网格列:

           {
                field: "January",
                title: "January",
                aggregates: ["sum"],
                filterable: false,
                resourcename: "january",
                type: "currency",
                footerTemplate: function (data) {
                    return "<div style='white-space:initial;float:right'>" + kendo.toString(data.January.sum, "n0") + "</div>";
                }
            }

图片:enter image description here

问题: 如何解决这个 html 字符串问题?

谢谢......

最佳答案

确保您的dataSource包含 sum aggregate 在您希望获得 sum 的列上运行函数的:

dataSource: {
  data: [
    { item: "AB", january: 12.24 },
    { item: "CD", january: 22.23 }
  ],
  aggregate: [
    { field: "january", aggregate: "sum" }        
  ]
}

然后声明你的 footerTemplate 在您希望显示值的列上:

columns: [
  { field: "item" },
  { field: "january",
    type: "currency",
    footerTemplate: "Sum: #: sum #"
  }
]

完整的 Dojo 工作示例 here .

编辑 - 右对齐 footerTemplate 中的内容

网格:

footerTemplate: "<div style='text-align: right'>Sum: #: sum #</div>"

Excel 导出 - 包括以下内容 excelExport 网格定义中的函数:

excelExport: function(e) {
    var rows = e.workbook.sheets[0].rows;

    for (var ri = 0; ri < rows.length; ri++) {
      var row = rows[ri];

      if (row.type == "group-footer" || row.type == "footer") {
        for (var ci = 0; ci < row.cells.length; ci++) {
          var cell = row.cells[ci];
          if (cell.value) {                
            cell.value = $(cell.value).text();
            // Set the alignment
            cell.hAlign = "right";
          }
        }
      }
    }
  }

hAlign 是设置为对齐文本的属性,但是如果使用 Kendo 版本 2015.3/更新版本,则此属性已被弃用,因此请使用 textAlign 相反。

我还更新了 Dojo example以反射(reflect)这些变化。

关于javascript - 导出 Kendo Grid 时 footerTemplate 显示 html 字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44067631/

相关文章:

javascript - 如何在 jQuery 中显示内容之前显示 setTimeout 图像?

asp.net - 剑道 TabStrip : Getting the Selected Index on the Selected event (MVC 4)

javascript - Kendo 网格更改多个选定的单元格值

javascript - 我应该使用 !== 还是 ==!检查不等于时?

javascript - jQuery - 如何填充(数据注入(inject))嵌套 SheepIt 表单

javascript - 将克隆的元素添加到 ng-repeat

html - 尝试交换标签的顺序会改变 Bootstrap/CSS 的功能

html - Chrome 在页面中插入一个 DAPPlugin id 来增加页面长度?

printing - 如何以编程方式解锁 Kendo-UI Grid 多列标题

javascript - 如何使用 Jquery 在 ASP.Net 中制作对话框?