【问题标题】:How to set the number format for hyperlinks in kendo grid column如何设置剑道网格列中超链接的数字格式
【发布时间】:2017-03-14 12:30:09
【问题描述】:

我想为剑道网格中的列应用数字格式。该列定义是:

{
    field: "WeekEndGrossUSD",
    title: dashBoardColumNames[0].WeekendGrossUSD,
    headerTemplate: "<span class= 'headerTooltip' id='WEEKEND GROSS (USD)'>" + dashBoardColumNames[0].WeekendGrossUSD + "</span>",
    format: "{0:n0}",
    type: "number",
    attributes: { style: "font-size: 0.85em;text-align:right" },
    footerTemplate: "<span id='WeekendGrossSUM'></span>"
    //width: 120
},
{
    field: "WeekGrossUSD",
    title: dashBoardColumNames[0].WeekGrossUSD,
    headerTemplate: "<span class= 'headerTooltip' id='WEEK GROSS (USD)'>" + dashBoardColumNames[0].WeekGrossUSD + "</span>",
    format: "{0:n0}",
    type: "number",
    attributes: { style: "font-size: 0.85em;text-align:right" },
    footerTemplate: "<span id='WeekGrossSUM'></span>"
    //width: 120
},
{
    field: "CumulativeGrossUSD",
    title: dashBoardColumNames[0].CumeGrossUSD,
    headerTemplate: "<span class= 'headerTooltip' id='CUME GROSS (USD)'>" + dashBoardColumNames[0].CumeGrossUSD + "</span>",
    format: "{0:n0}",
    type: "number",
    template: '<a  class="titlehyperLink" style="color:blue"  id="cumeTemplate">${CumulativeGrossUSD}</a>',
    attributes: { style: "font-size: 0.85em;text-align:right" },
    width: 120,
}

上述列定义具有将文本转换为数字格式的格式属性。但是在将超链接列应用到“CumulativeGrossUSD”文件后,数字格式不适用。它错过了逗号数字的格式。请参考屏幕截图

点击超链接代码

$(self.TitleViewGridID).on("click", "#cumeTemplate", function (e) {
    var grid = $(self.TitleViewGridID).data("kendoGrid");
    var dataItem = grid.dataItem($(e.currentTarget).closest("tr"));
    sessionStorage.setItem("IsDashboardCumeClicked", true);
    window.location.href = "/International/TerritoryTitleList?TitleId=" + dataItem.TitleId;
});

如果我删除上述语法中的标题模板,它会给出数字格式,用逗号分隔。但是,如果我应用了标题模板,它不会给出逗号单独的格式。找到随附的屏幕截图。

【问题讨论】:

  • 您未显示的其余代码一定有问题。这是一个使用您提供的列定义的 Dojo,数字用逗号格式化:dojo.telerik.com/@Stephen/Uyobi。你能修改 Dojo 来复制你的问题吗?

标签: javascript user-interface kendo-ui kendo-grid


【解决方案1】:

列format 仅在您不使用列template 时有效。否则,格式化应该手动完成,例如在模板代码中使用kendo.toString()。

template: '<a>#= kendo.toString(CumulativeGrossUSD, "n0") #</a>'

附带说明,不要在列模板 ("cumeTemplate") 中使用静态 ID,因为它们会重复并导致 HTML 标记无效。您也无法将点击处理程序正确附加到所有超链接。请改用自定义 CSS 类。

【讨论】:

  • 但是如果我在过滤结果时添加了字符串格式,我们必须应用数字过滤器。如果我应用字符串,它将采用字符串格式
  • 我不明白您的评论,但我已经用您的新列定义更新了我的 Dojo,并应用了@dimodi 的 toString() 答案以显示正确格式的数字。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多