我有一个显示金额的Kendo Grid,但DataSource中的数据返回4个小数位。
DataSource数据如下所示:
{ totalDollars: 1513.1548 },
{ totalDollars: 158.2903 },
{ ... }
所以为了正确显示数字,我使用列格式......
columns: [
{ field: 'totalDollars', format: '{0:c2}' },
{ ... }
]
但现在我想过滤这个专栏。如果我使用"Is Equal To"
159.29
进行过滤,则会失败。
我使用4位小数并使用column.filterable.ui
:
columns: [
{
field: 'totalDollars',
format: '{0:c2}',
filterable: {
ui: function(e) {
element.kendoNumericTextBox({
format: "n4",
decimals: 4
});
}
}
}
]
但这没有用,因为用户不知道最后2位小数。所以我需要它在过滤时最多只使用2位小数。
这可能吗?
JSFiddle here - 请注意,使用7133.03
按“单身成本”进行过滤不起作用,但7133.0332
不起作用。我希望7133.03
能够工作。
答案 0 :(得分:2)
我已为您更新了小提琴http://jsfiddle.net/53pqe3mo/2/
但实质上,您可以通过添加以下内容来覆盖返回值的默认解析器:
DefaultMonoCPP: {
editable: false,
type: "number",
parse: function(e)
{
console.log(e);
return kendo.parseFloat(kendo.toString(e,"c2"));
}
我添加了console.log行只是为了向您显示实际传入的值是数据源提供的原始值。
这需要一点点发现,但这个链接应该有所帮助:
http://docs.telerik.com/kendo-ui/api/javascript/data/model#methods-Model.define
编辑:
根据评论更新答案。
供将来参考使用此链接:
http://docs.telerik.com/kendo-ui/framework/globalization/numberparsing