格式化Kendo网格列过滤器的百分比 [英] Format Kendo grid column filter for percentages

查看:161
本文介绍了格式化Kendo网格列过滤器的百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个剑道网格,并且我的数据源数据返回的数字带有未知的小数位.因此,我在数据源上使用了一个解析函数来对此进行补偿.

I have a kendo grid and my datasource data returns number with unknown decimal places. So I'm using a parse function on the datasource to compensate for that.

DefaultMonoCPP: {
    editable: false,
    type: "number",  
    parse: function(e) {
        return  kendo.parseFloat(kendo.toString(e,"p4")); 
    }
}

现在,当我进行过滤时,我不希望它自动将百分比乘以100.因此,我在列上设置了filterable.

Now when I filter, I don't want it to automatically multiply the percentage by 100. So I have filterable set on the columns.

    {
        field: "DefaultMonoCPP",
        title: "Mono Cost",
        format: '{0:p4}',
        filterable: {
            ui: function(e) {
                e.kendoNumericTextBox({
                    //format: "{0:p4}",
                    //format: "p4",
                    format: "##.0000 \\%",
                    decimals: 4
                });
            }
        }
    }

但是这弄乱了过滤后的数字(1.2700%=> 1.27).因此过滤失败.

But this messes up the filtered number (1.2700% => 1.27). So filtering fails.

JSFiddle进行澄清: http://jsfiddle.net/dmathisen/mecny50f/

JSFiddle for clarification: http://jsfiddle.net/dmathisen/mecny50f/

有什么办法可以使解析和可过滤功能一起正常工作吗?

Is there any way to have both the parse and filterable work correctly together?

推荐答案

我的建议是将数字文本框设置为百分比格式,并将步长设置为0.01,以使其每次递增/递减1%.如果您担心用户输入整数百分比,请在change事件中处理它.

My suggestion would be to format the numeric textbox as a percentage and set the step to 0.01 so that it increments/decrements 1% at a time. If you're worried about the user typing in a percentage as a whole number, handle it in the change event.

e.kendoNumericTextBox({
    format: '{0:p4}',
    step: 0.01,
    decimals: 4,
    change: function () {
        var val = this.value();
        if (val > 1) {
            this.value(val / 100);
            this.trigger("change");
        }
    }
});

JSFiddle

这篇关于格式化Kendo网格列过滤器的百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆