动态列上的 Kendo 网格过滤器 [英] Kendo Grid Filter on a dynamic column

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

问题描述

我正在研究 Kendo Grid,它有一个 Status 列,该列是其他几个列的状态的聚合.我将各个状态作为整数值进行跟踪,并且聚合列应显示最少的状态.现在,使用模板,我可以很好地呈现 Status 列的文本,但是,问题是我希望此列可过滤.这在计算值时不起作用.

I am working on a Kendo Grid which has a Status column that is an aggregate of statuses of several other columns. I track the individual statuses as integer values and the aggregate column should show the least of the statuses. Now, using template, I am able to render the text for the Status column fine, however, the problem is that I want this column to be filterable. This is not working as the value is calculated.

在数据源中,这就是我声明自定义字段的方式,

In DataSource, this is how I have declared the custom field,

schema: {
    model: {
        Status: function () {
            return helper.GetStatus(this.EntriesStatus);
        }
    }
}

这就是我在列定义中使用它的方式,

This is how I used it in the Column definition,

{
    field: "Status",
    title: "Status",
    width: "100px",
    filterable: true,
    template: kendo.template("#if (HasError) {# <strong class='clrRed' > #= Status() # </strong> #} else { # #= Status() # #} #"),
    hidden: false,
    menu: false
}

谁能指出我哪里出错了或更有效的出路?

Could anyone point out where I am going wrong or a more efficient way out?

推荐答案

不是将 Status 定义为 model 中的一个函数,而是将其添加到 model 中.解析 作为计算域.例如:

Instead of defining Status as a function in the model, add it in model.parse as a computed field. Ex:

schema: {
    parse: function (d) {
        $.each(d, function (idx, elem) {
            elem.Status = helper.GetStatus(elem.EntriesStatus);
        });
        return d;
    }
}

然后在模板中删除():

template: kendo.template("#if (HasError) {# <strong class='clrRed' > #= Status # </strong> #} else { # #= Status # #} #"),

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

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