繁体   English   中英

kendo ui grid row filterable 不会过滤复杂的对象

[英]kendo ui grid row filterable wont filter an complex object

我正在尝试对列 Mid 进行行过滤,该列是一个包含两个属性的复杂对象 { Id: 0, Name: "Select MID" }

现在,当我在过滤器输入中输入一些值时,我会得到这个例外

VM1033:3 Uncaught TypeError: (d.Mid || "").toLowerCase 不是函数

我猜这是因为 Mid 是一个对象而不是一个 premetive 类型

有任何想法吗 ?

感谢你

这是我的网格:

$("#grid_1").kendoGrid({
    dataSource: {
        dataType: "d",
        transport: {
            read:  {
                url: crudServiceBaseUrl + "/Read",

            },
            update: {
                url: crudServiceBaseUrl + "/Update",
                type: "post",
                contentType: "application/json; charset=utf-8",
                complete: function (e) {

                    jQuery("#load_balancer_grid").data("kendoGrid").dataSource.read();

                }
            },
            create: {
                url: crudServiceBaseUrl + "/Create",
                type: "post",
                contentType: "application/json; charset=utf-8",
                complete: function (e) {

                    jQuery("#load_balancer_grid").data("kendoGrid").dataSource.read();

                }
            },
            destroy: {
                url: crudServiceBaseUrl + "/Delete",
                dataType: "d"
            },
            parameterMap: function (options, operation) {

            }

        },

        batch: true,
        pageSize: 100,
        schema: {
            model: {
                id: "MidGroupId",
                fields: {
                    MidGroupId: { validation: { required: true }, editable: true, type: "number" },
                    Mid: { validation: { required: true }, editable: true, defaultValue: { Id: 0, Name: "Select MID" } },

                    RouteSales: {
                        type: "boolean",
                        parse: function (value) {
                            if (value != null) {
                                return value || false;
                            }
                            return value;
                        },
                        nullable: true
                    },
                    RouteRebills: { type: "boolean" },
                    QueueRebills: { type: "boolean" },
                  //  ResetCounters: { type: "boolean" },
                    
                }
            }
        }
    },
    sortable: true,
    batch: true,

    groupable: true,
    pageable: {
        refresh: true,
        pageSizes: true,
        buttonCount: 5
    },

        filterable: {
                    mode: "row"
                },
    toolbar: kendo.template($("#template").html()),

    edit: function(e) {
        if (e.model.isNew() == false) {
         
            $(e.container.find("input[name=MidGroupId]")).attr('disabled', 'disabled');
            $(e.container.find("input[name=Mid]")).attr('disabled', 'disabled');
            $(e.container.find("input[name=CardType]")).attr('disabled', 'disabled');
        }
    },
    columns: [
       {
           field: "MidGroupId", type: "number"
       },
              {
                  field: "Mid", editor: MidDropDownEditor, template: "#=Mid.Name#", title: "MID",
                  filterable: {
                      cell: {
                          dataSource: {
                              type: "d",
                              transport: {
                                  read: crudServiceBaseUrl + "/GetMidsOptions"
                              }
                          }
                           ,
                          dataValueField: "Id",
                          dataTextField: "Name"
                      }
                  }

              }

            
    ],
    editable: true
});

我试图过滤一个对象

每个数据源 API没有直接在数据源上的 dataType 属性,因此以下部分不正确,因此这可能是您出错的原因:

dataSource: {
    dataType: "d",

dataType 可以在 dataSource 传输的传输 CRUD 内部更深地定义,因为您已经在那里有了它。 我没有试过把复杂的对象放到网格列中,为什么不在服务器上做呢? 在服务器上创建原始属性并在网格中轻松使用它是最自然的。

我也遇到了这个问题。 解决方案是在更改处理程序触发时更新编辑器中的 model.dirtyFilds。 看起来像:

function MidDropDownEditor(container, options){
$(`<input id="MidEditor" name="Mid" data-bind="value:Mid" />`)
        .appendTo(container)
        .kendoDropDownList({
            autoBind: false,
            filter: "startswith",
            dataTextField: "Name",
            dataValueField: "Id",            
            enable: false,
            change: function(){
                if (options.model.dirtyFields['Mid']) {
                    options.model.dirtyFields['Mid.Name'] = true;
                }
            }
});

在列设置中,您应该设置属性“字段”,如“Mid.Name”。

这个对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM