【问题标题】:KendoGrid - Filtering on a property of objectKendoGrid - 过滤对象的属性
【发布时间】:2020-11-18 02:01:52
【问题描述】:

这是我的 KendoGrid:

    $scope.gridEltCompoOptions = {
                dataSource: {
                    transport: {
                        ...
                    },
                    schema: {
                        model: {
                            id: 'IdElement',
                            fields: {
                                GroupeActes: { defaultValue: { IdGroupeActes: null, Libelle: ' ' } }
                            }
                        }
                    }
                },
                sortable: true,
                resizable: true,
                filterable: {
                    mode: 'row'
                },
                columns: [{
                    field: 'GroupeActes',
                    title: "Groupe d'actes",
                    template: function (dataItem) {
                        return kendo.toString(dataItem.GroupeActes.Libelle);
                    }
                }, ]

我想在属性 Libelle 上过滤我的字段“GroupeActes”(GroupeActes 是一个对象),但实际上过滤器采用了整个对象。

当我尝试过滤时,我有一个 Js 错误

未捕获的 TypeError: (d.GroupeActes || "").toLowerCase 不是函数

问题很清楚,过滤器正在获取整个对象,而不是属性 Libelle。 我过去 4 小时尝试了我在谷歌上找到的所有解决方案,但没有任何效果

我的对象 GroupeActes 是这样的: var GroupeActes = { 集团行动:{ 利贝尔:“” } } 有两个 groupeActes 级别

我在 2015 年看到一个管理员的帖子,说这种过滤器是不可能的, 但我也看到了这种解决方案: https://docs.telerik.com/kendo-ui/knowledge-base/grid-filter-column-with-dropdownlist

(if(e.field == "Category" && e.filter !== null){) 在示例中 我试图做类似的事情:如果字段==“groupeActes”=>所以我想过滤Libelle属性, 但我没有成功

有人可以帮帮我吗?

非常感谢

【问题讨论】:

    标签: filter kendo-ui kendo-grid


    【解决方案1】:

    你看过这篇文章吗:https://docs.telerik.com/kendo-ui/knowledge-base/enable-operations-for-object-column

    我相信您可以通过将列字段设置为"GroupeActes.Libelle" 而不是使用列模板来完成您想要的:

    columns: [
        {
            field: 'GroupeActes.Libelle',
            title: "Groupe d'actes",
        }, 
    ],
    

    看到这个DEMO

    【讨论】:

    • 谢谢你的回答,事实上我的项目需要整个对象,我已经尝试过这个解决方案,但是当我调用我的服务器后,我丢失了我的对象的所有信息
    • 实际上我的字段必须是整个对象,我必须在我的网格(使用模板)中只显示属性“Libelle”,问题是我想过滤属性 Libelle to => 但正如您所知,过滤器采用“字段:”上给出的对象:
    • @blackstar012 - 你可以添加一个字符串列来显示和过滤 Libelle,然后隐藏对象列吗?
    猜你喜欢
    • 2023-04-09
    • 2015-04-25
    • 2018-10-26
    • 2017-09-22
    • 1970-01-01
    • 2018-04-07
    • 2019-05-29
    • 2013-11-19
    • 1970-01-01
    相关资源
    最近更新 更多