jQuery KendoUI Grid 十进制数列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15591628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 15:23:26  来源:igfitidea点击:

KendoUI Grid Decimal number column

jquerykendo-uitelerikkendo-grid

提问by imperium2335

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.

我有一个重量列(以公斤为单位)。当用户点击它时,我需要让他们能够输入 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.

我的问题是目前它只允许他们把它放在 2 个地方,但显示为 3 个地方。您可以将一个数字输入到多个小数位,但是当它保存时,它会将其四舍五入到 2 位。

My column is set up like so:

我的专栏是这样设置的:

...
{
        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.

我尝试了一些东西,但没有任何效果。

回答by OnaBai

Several questions (afaik):

几个问题(afaik):

  1. Format in columns is not defined as n4but 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, stepso you should define an editor function.
  1. 列中的格式未定义为,n4而是定义为{0:n4}.
  2. 格式不仅适用于数字的格式,还可能包括一些文本。前任:{0:n4} Kg.
  3. 对于数字列,不能将属性指定为decimalsstep因此您应该定义一个编辑器函数。

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

另外,我不明白你的小数和舍入问题。

What I suggest is define the columns as:

我的建议是将列定义为:

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

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

(假设您想要三个十进制精度)并定义numberEditor为:

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