Kendo 网格列号格式
Kendo grid column number formatting
如果我们绑定 2 个数据值,如何在 kendo 列中设置数字格式?在我的示例中,我必须将值与单位绑定,因此我需要一个带有 2 位小数的值。
我的代码如下所示:
{
field: "Quantity",
title: "Value ",
width: "70px",
type: "number",
format:"{0:n2}",
template: "#:Quantity# #:Unit#",
attributes:{style:"text-align:right;"}
},
如果不将它绑定到 unit,它工作得很好,但是对于 unit 我有一个问题。提前致谢
这会将 Quantity
格式化为显示为带 2 位小数的数字
template: '#= kendo.toString(Quantity, "n2")# #=Unit#'
以上给出的答案很好,但您也可以通过使用单独的 kendo 模板获得更多自定义选项来获得相同的结果。
template: kendo.template($("#quantity-tmplt").html())
定义您的模板。
<script type="text/x-kendo-template" id="quantity-tmplt">
<div>#= kendo.toString(Quantity, "n2") #</div>
</script>
有关详细信息,请阅读 KendoGrid Column Template
如果我们绑定 2 个数据值,如何在 kendo 列中设置数字格式?在我的示例中,我必须将值与单位绑定,因此我需要一个带有 2 位小数的值。 我的代码如下所示:
{
field: "Quantity",
title: "Value ",
width: "70px",
type: "number",
format:"{0:n2}",
template: "#:Quantity# #:Unit#",
attributes:{style:"text-align:right;"}
},
如果不将它绑定到 unit,它工作得很好,但是对于 unit 我有一个问题。提前致谢
这会将 Quantity
格式化为显示为带 2 位小数的数字
template: '#= kendo.toString(Quantity, "n2")# #=Unit#'
以上给出的答案很好,但您也可以通过使用单独的 kendo 模板获得更多自定义选项来获得相同的结果。
template: kendo.template($("#quantity-tmplt").html())
定义您的模板。
<script type="text/x-kendo-template" id="quantity-tmplt">
<div>#= kendo.toString(Quantity, "n2") #</div>
</script>
有关详细信息,请阅读 KendoGrid Column Template