Kendo Grid Filter on a dynamic column

若如初见. 提交于 2019-12-08 09:45:56

问题


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?


回答1:


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;
    }
}

And then in the template remove ():

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


来源:https://stackoverflow.com/questions/16520479/kendo-grid-filter-on-a-dynamic-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!