【发布时间】:2015-09-26 15:20:42
【问题描述】:
在此Kendo Grid demo 中,如果您编辑“库存商品”下的数字并添加多个小数(尝试 2.203848),它会将其截断为 2.20。看起来这是默认行为。
而且我知道我们可以用{0:n4} 指定十进制格式,例如。
但如果小数位数未知或可以变化怎么办?有没有办法让网格使用用户输入的确切数字?
【问题讨论】:
标签: javascript kendo-ui telerik kendo-grid
在此Kendo Grid demo 中,如果您编辑“库存商品”下的数字并添加多个小数(尝试 2.203848),它会将其截断为 2.20。看起来这是默认行为。
而且我知道我们可以用{0:n4} 指定十进制格式,例如。
但如果小数位数未知或可以变化怎么办?有没有办法让网格使用用户输入的确切数字?
【问题讨论】:
标签: javascript kendo-ui telerik kendo-grid
要在网格中进行这项工作,您需要使用自定义编辑器。将小数位数设置为足够高的数字,并确保您的字段格式有足够的位置。这个很好的答案here 稍作调整可以解决您的问题。
function numberEditor(container, options) {
$('<input name="' + options.field + '"/>')
.appendTo(container)
.kendoNumericTextBox({
decimals: 8,
step : 0.01
});
}
$("#grid").kendoGrid({
dataSource: dataSource,
navigatable: true,
pageable: true,
height: 550,
toolbar: ["create", "save", "cancel"],
columns: [
"ProductName",
{ field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: 120 },
{ field: "UnitsInStock", title: "Units In Stock", format: "{0:0.#########}", width: 120, editor: numberEditor },
{ field: "Discontinued", width: 120 },
{ command: "destroy", title: " ", width: 150 }],
editable: true
});
});
【讨论】:
kendo ui 网格支持在直接调用 kendo.format() 时可以使用的任何格式。相关文档可在 here 获得。
你要找的格式是
{0:$###,###,###,###,###,###,###,###.##############}
您需要将其填充到您想要支持的小数位数。
【讨论】: