问题描述
我有一列重量(以公斤为单位).当用户点击它时,我需要让他们能够输入 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 个位置.您可以将一个数字输入到多个小数位,但保存时会将其四舍五入到 2 位.
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.
我的专栏是这样设置的:
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.
推荐答案
几个问题 (afaik):
Several questions (afaik):
- 列中的格式未定义为
n4
,而是定义为{0:n4}
. - 格式不仅适用于数字的格式,还可能包括一些文本.例如:
{0:n4} 公斤.
- 对于数字列,不能将属性指定为
decimals
、step
,因此您应该定义一个编辑器函数.
- Format in columns is not defined as
n4
but as{0:n4}
. - Formats are not just for the format of the number but might also include some text. Ex:
{0:n4} Kg.
- 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 Grid 十进制数列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!