如何在kendo网格列中设置超链接的数字格式

时间:2016-11-01 11:08:32

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

我想在kendo网格中应用列的数字格式。该列定义是:

{
    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,
}

上面的列定义具有将文本转换为数字格式的format属性。但在将超链接列应用于&#34; CumulativeGrossUSD&#34;提交的数字格式不适用。它用comma错过了数字的格式化。请参考屏幕截图

点击超链接的代码

$(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;
});

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

enter image description here

1 个答案:

答案 0 :(得分:1)

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

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

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

相关问题