我有带有footerTemplate的Kendo网格。我已成功将此表格导出为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>";
                }
            }


图片:javascript - 当导出Kendo Grid时,footerTemplate显示html字符串吗?-LMLPHP

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

谢谢.......

最佳答案

确保dataSourcesum列包含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以反映这些更改。

08-19 06:05