javascript - Kendo Grid numbers truncate to 2 decimal places. How to make it respect what the user entered? - Stack Overflow

In this Kendo Grid demo, if you edit the numbers under "Units in Stock" and add multiple deci

In this Kendo Grid demo, if you edit the numbers under "Units in Stock" and add multiple decimals (try 2.203848), it'll truncate it to 2.20. It looks like that's the default behavior.

And I know that we can specify the decimal format with {0:n4}, for example.

But what if the number of decimals is unknown or can vary? Is there any way to make the grid use the exact number that the user enters?

In this Kendo Grid demo, if you edit the numbers under "Units in Stock" and add multiple decimals (try 2.203848), it'll truncate it to 2.20. It looks like that's the default behavior.

And I know that we can specify the decimal format with {0:n4}, for example.

But what if the number of decimals is unknown or can vary? Is there any way to make the grid use the exact number that the user enters?

Share Improve this question asked Jul 8, 2015 at 15:36 dmathisendmathisen 2,3425 gold badges37 silver badges65 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6 +50

To make this work in a grid, you need to use a custom editor. Set the number of decimals to a high enough number and make sure your field format has enough places. This great answer here tweaked a bit solves your problem.

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 },
        { mand: "destroy", title: "&nbsp;", width: 150 }],
    editable: true
});

});

The kendo ui grid supports any format that you can use when calling kendo.format() directly. The documentation for that is available here.

The format you are looking for is

{0:$###,###,###,###,###,###,###,###.##############} 

You will need to pad that out to however many decimal places you want to support.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743732932a4497750.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信