How to set the number format for hyperlinks in kendo grid column

北城余情 提交于 2020-01-05 05:06:55

问题


I want to apply the number format for a column in kendo grid. That column definition is:

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

The above column definitons having the format attribute which converts text into number format. But after applying the hyperlink column to "CumulativeGrossUSD" filed the number format is not applying. it's missed the formatting of number with comma.please refer the screen shot

Code for clicking hyper link

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

If i remove the header template in the above syntax it's giving the number format separate with comma. But if i applied the header template it's not giving the comma separate format. Find the attached screen shot.


回答1:


Column format works only if you are NOT using a column template. Otherwise, the formatting should be done manually, e.g. by using kendo.toString() inside the template code.

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

On a side note, do not use static IDs in column templates ("cumeTemplate"), because they will duplicate and lead to invalid HTML markup. You will also not be able to attach a click handler properly to all hyperlinks. Use custom CSS classes instead.



来源:https://stackoverflow.com/questions/40358863/how-to-set-the-number-format-for-hyperlinks-in-kendo-grid-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!