KendoUI网格十进制数列 [英] KendoUI Grid Decimal number column

查看:127
本文介绍了KendoUI网格十进制数列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一列重量(以千克为单位).当用户单击它时,我需要使他们能够以3位十进制数输入.

I have a column for weight (in Kg). When the user clicks on it I need to enable them to be able to put in decimal number with 3 places.

我遇到的问题是,目前仅允许他们将其放置在2个位置,但显示为3个位置.您可以输入数字到小数点后一位,但保存时会将其四舍五入到第二位.

The problem I have is at the moment it only allows them to put it in to 2 places, but shows as 3 places. You can type in a number to many decimal places but when it saves it will round it to 2 places.

我的栏设置如下:

...
{
        field: "weight",
        title: "Weight",
        width: 40,
        format: "n4",
        decimals: 4,
        step: 0.001,
        template: "#= weight.toFixed(3)+'kg' #"
}
...

我尝试了几件事,但是没有用.

I have tried a few things but none work.

推荐答案

几个问题(afaik):

Several questions (afaik):

  1. 列中的格式未定义为n4,而是定义为{0:n4}.
  2. 格式不仅适用于数字格式,还可能包含一些文本.例如:{0:n4} Kg.
  3. 对于数字列,无法将属性指定为decimalsstep,因此您应该定义编辑器功能.
  1. Format in columns is not defined as n4 but as {0:n4}.
  2. Formats are not just for the format of the number but might also include some text. Ex: {0:n4} Kg.
  3. For numeric columns, is not possible to specify attributes as decimals, step so you should define an editor function.

此外,我不理解您的小数和舍入问题.

In addition, I don't understand your problems with decimals and round.

我建议将列定义为:

{
    field: "weight",
    title: "Weight",
    width: 40,
    editor: numberEditor,
    format: '{0:n3} Kg.'
}

(假设您希望使用三位小数精度),并将numberEditor定义为:

(assuming that you want three decimal precision) and define numberEditor as:

function numberEditor(container, options) {
    $('<input name="' + options.field + '"/>')
            .appendTo(container)
            .kendoNumericTextBox({
                format  : "{0:n3}",
                decimals: 3,
                step    : 0.001
            });
}

这篇关于KendoUI网格十进制数列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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