如何在KendoUI MVC网格中添加千位逗号分隔符 [英] How to add in KendoUI MVC Grid a thousand comma separator

查看:211
本文介绍了如何在KendoUI MVC网格中添加千位逗号分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Grid中显示1000,例如1,000(必须有逗号).初始数据类型为字符串.我需要千位逗号分隔符.

I want to display 1000 like 1,000 in Grid (Must have commas). Initial data type is string. I need thousand comma separator.

我有与在相同的问题 如何更改长变量的显示格式?.但是我的数据类型是字符串.

I have the same questions as in How to change display format of long variable?. But my data type is string.

在本主题中,他们对KendoUI MVC网格没有明确的答案 千位逗号分隔符.

In this topic they did not have clear answer for KendoUI MVC Grid for thousand comma separator.

我有KendoUI网格

I have KendoUI Grid

@(Html.Kendo().Grid((IEnumerable<MyApp.Models.MyModel>)ViewBag.QualReq)
    .Name("MyGrid")
    .Columns(columns =>
        { 
        columns.Bound(p => p.Actual); 
        })
    .DataSource(d => d
        .Ajax()
    )
)

模型

public class MyModel
{ 
    public virtual string Actual { get; set; } 
}

控制器

    [OutputCache(Duration = 60)]
    public ActionResult MyActionMethod(int RankId = 0)
    { 
        . . .                  
        ViewBag.QualReq = qualificationRequirements.Where(x => x.RankID == RankId).ToList();
        . . .

我在数字格式设置"主题中没有找到有关MVC网格的任何信息. http://docs.telerik.com/kendo-ui/framework/globalization/数字格式

I have not found any information for MVC Grid in Number Formatting topic. http://docs.telerik.com/kendo-ui/framework/globalization/numberformatting

推荐答案

您可以使用ClientTemplate在网格本身上进行此操作.

You can do this on the grid itself with ClientTemplate.

@(Html.Kendo().Grid((IEnumerable<MyApp.Models.MyModel>)ViewBag.QualReq)
    .Name("MyGrid")
    .Columns(columns =>
        { 
            columns.Bound(p => p.Actual).ClientTemplate("#= kendo.format('{0:N0}', parseInt(Actual)) #"); 
        })
    .DataSource(d => d
        .Ajax()
    )
)

如果此字段有时包含非数字数据,则您可能需要包括一些逻辑以解决这些情况.

If this field sometimes contains non-numeric data, you may want to include some logic to account for those cases.

这篇关于如何在KendoUI MVC网格中添加千位逗号分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆