【发布时间】:2017-04-06 08:34:29
【问题描述】:
我需要在我的 kendoGrid 中以十进制 (2) 格式显示数字。但到目前为止似乎没有任何效果。所以我需要帮助理解为什么。我搜索了论坛,但很简单 '将类型字段设置为数字并使用格式:“{0:n2}”'不起作用。我从一个字段值有很多小数的 JSON 中获取我的数据。所以我希望它们在我的 kendoGrid 中只有 2 位小数。
这是我的代码,我尝试让它工作失败
var gridStavke = $("#gridItems").kendoGrid({
scrollable: true,
sortable: true,
resizable: true,
dataSource: {
schema: {
model: {
fields: {
PDV25 : { type : "number" },
PDV3 : { type : "number" },
PDV28 : { type : "number" }
}
}
}
},
height: $(document).height() - 190,
columns: [
{field: "product", title: "Product"},
{field: "price", title: "Price"},
{field: "base", title: "Base"},
{field: "count", title: "Count",footerTemplate:"total"},
{field: "PDV25", title: "PDV 25%",format:"{0:n2}"},
{field:"PDV3",title:"PDV 3%",format:"{0:n2}", editor:function(container,options){$('<input />').appendTo(container).kendoNumericTextBox({format:"n",decimals:2});}},
{field: "PDV28", title: "PDV 28%", editor:numberEditor}
]
}).data("kendoGrid");
function numberEditor(container, options) {
$('<input name="' + options.field + '"/>')
.appendTo(container)
.kendoNumericTextBox({
format : "{0:n2}",
decimals: 2,
step : 0.01
});
}
JSON
"data":[
{
"product":"Med",
"price":"40.3",
"count":"1",
"base":"238.42628640776698",
"PDV25":"8.059999999999999",
"PDV28":"54.68750000000001",
"PDV3":"0.32621359223300966"
},
{
"product":"Sir",
"price":"250",
"count":"1",
"base":"238.42628640776698",
"PDV25":"8.059999999999999",
"PDV28":"54.68750000000001",
"PDV3":"0.32621359223300966"
},
{
"product":"Mlijeko",
"price":"11.2",
"count":"2",
"base":"238.42628640776698",
"PDV25":"8.059999999999999",
"PDV28":"54.68750000000001",
"PDV3":"0.32621359223300966"
}
]
编辑:我找到了问题的解决方案。我需要在 {field...} 参数中添加模板:'#= parseFloat(namefield).toFixed(2)#'。
【问题讨论】:
标签: kendo-ui kendo-grid