【问题标题】:how to set comma for double number in kendoGrid如何在kendoGrid中为双数设置逗号
【发布时间】:2012-12-10 10:09:40
【问题描述】:
$("#kendoGridView").kendoGrid({
                            width: 1500,
                            dataSource: data.d,
                            resizable: true,
                            rowTemplate:
                            height: 790,
                            dataBound: dbGrid,
                            selectable: true,
                            columns: [
                                            { title: 'Revenue', field: 'Revenue', width: '20%', sortable: true },
                                            { title: 'postals', field: 'postals', width: '12%', sortable: true },
                                            { title: 'MQC', field: 'MQC', width: '12%', sortable: true },
                                      ]
                        });

我正在将数据库中的值绑定到 kendoGrid。我想为网格中的所有列号设置逗号分隔符(例如 458690 到 4,58,690)。我已经阅读了 kendoui 中的 NumberFormating 概念,但我没有足够的信息。如何设置。

【问题讨论】:

    标签: jquery kendo-ui


    【解决方案1】:

    这取决于您使用的文化,但基本上,您只需根据the documentation 在列中添加一个字段format

    $("#kendoGridView").kendoGrid({
        width: 1500,
        dataSource: data.d,
        resizable: true,
        rowTemplate:
        height: 790,
        dataBound: dbGrid,
        selectable: true,
        columns: [
            // Here I have added the format field
            { title: 'Revenue', field: 'Revenue', width: '20%', sortable: true, format: "{0:c3}" },
            { title: 'postals', field: 'postals', width: '12%', sortable: true },
            { title: 'MQC', field: 'MQC', width: '12%', sortable: true },
        ]
    });
    

    我创建了这个小提琴:http://jsfiddle.net/AHCbq/


    编辑:

    似乎即使使用正确的文化,某些十进制字段在网格中也没有正确解释,我们无法应用自定义格式。

    为了解决这个问题,我们必须创建一个自定义解析器,以强制将该字段视为十进制字段。我已经更新了我以前的小提琴:http://jsfiddle.net/AHCbq/7/

    这是通过在datasource.schema.parse 中添加一个解析器来实现的,它将字符串转换为数字:

    parse : function(data) {
        $.each(data.d.results, function(i, val) {
            // Here I convert the string in a decimal number
            val.Freight = +val.Freight;
        });
        return data;
    }
    

    【讨论】:

    • hello samuel 这个 839009.378(double) 值来自数据库。我已经为列写了格式:“{0:c3}”,但是“,”分隔符不适用于这些值。是这一行吗代码 kendo.culture("en-US");或 kendo.culture("de-DE");有必要写吗?请回复
    • 这似乎不是强制性的......但我已经玩了一点格式,我已经看到他们的数据(我的小提琴依赖于剑道 UI 数据)包含一个小数列字段 - 货运 - 我们无法使用上述字段格式对其进行格式化。所以我更新了我的帖子以添加另一个解决方案......
    【解决方案2】:

    您可以尝试使用template for your column 并将其与kendo.format 方法结合使用。

    例如

     columns: [
         {
             field: "Salary",
             template: '#= kendo.format("{0:c}",Salary) #'
        }
     ]
    

    here的大部分东西都可以用,方法是受C#方法启发的。

    【讨论】:

    • 我已经采用了将图像绑定到网格的行模板。所以它不接受第二次。如果我评论行模板(用于图像),这工作正常......不可能使用网格的两行模板。?
    猜你喜欢
    • 1970-01-01
    • 2013-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-30
    • 2019-05-11
    • 2012-04-12
    相关资源
    最近更新 更多