kendo-ui - Kendo 网格数格式化为百分比问题

我使用以下方法显示格式化为百分比的数值:

columns.push(
            {
                field: key,
                hidden: false,
                format: "{0:p2}"
            });

当该字段应该显示 1.00% 时,它显示 100.00% 就像任何给定值一样 它添加零,另一个值是65.37% 输出为 6,537.00%

我缺少任何设置或格式有任何问题吗? 问题是我正在动态创建网格,因此无法显示完整的网格设置。

在上面你可以看到我正在推送列,这是一个数组,它将被传递给创建网格的函数。

最佳答案

请尝试使用以下代码片段。

<div id="grid"></div>
<script>
    $("#grid").kendoGrid({
        dataSource: {
            data: [
              { id: 1, increase: 1.00 },
              { id: 1, increase: 65.37 }
            ],
            schema: {
                model: {
                    id: "id",
                    fields: {
                        increase: { type: "number" }
                    }
                }
            }
        },
        columns: [
          { field: "id" },
          {
              field: "increase",
              template: '#=kendo.format("{0:p}", increase / 100)#'
          }
        ]
    });

</script>

如有任何疑问,请告诉我。

https://stackoverflow.com/questions/32881550/

相关文章:

python - 使用 python 请求在 HTTP POST 上规避错误 414

php - MDL- componentHandler.upgradeDom();在ajax调用之后

bash - 将 Bash Shell 变量传递给 Awk NR 函数

ruby-on-rails - 如何显示 Time.now 基于 TimeZone - Rails

matlab - 如何迭代matlab中稀疏矩阵中的元素?

vim - 如何在 Vim 中快速上下(ctrl u 和 ctrl d)重新映射到 ctrl j 和

python - 值错误 : continuous is not supported

regex - R 中 SQL LIKE 运算符的等价物

c# - 如何等待 UploadStringAsync 方法完成

oracle - PL/SQL - 计算重叠时间段之间的不同天数