1

我有这个网格

$("#address-grid").kendoGrid({
    dataSource: {
        transport: {
            read: {
                url: "operations/get_sales_reps_addresses.php?salesRepsId=" + salesRepsId,
                type: "GET"
            },
            update: {
                url: "operations/edit_address.php?salesRepsId=" + salesRepsId,
                type: "POST",
                complete: function (e) {
                    $("#address-grid").data("kendoGrid").dataSource.read();
                }
            },
            destroy: {
                url: "operations/delete_address.php",
                type: "POST",
                complete: function (e) {
                    $("address-grid").data("kendoGrid").dataSource.read();
                }
            },
            create: {
                url: "operations/add_address.php?salesRepsId=" + salesRepsId,
                type: "POST",
                complete: function (e) {
                    $("#address-grid").data("kendoGrid").dataSource.read();
                }
            },
        },
        schema: {
            data: "data",
            total: "data.length", //total amount of records
            model: {
                id: "SalesRepId",
                fields: {
                    AddressType: {
                        defaultValue: {
                            AddressTypeid: 1,
                            AddressTypeName: "Work"
                        }
                    },
                    Country: {
                        defaultValue: {
                            CountryId: 38,
                            CountryName: "Canada"
                        }
                    },
                    State: {
                        defaultValue: {
                            StateId: 4223,
                            StateName: "British Colombia"
                        }
                    },
                    City: {
                        defaultValue: {
                            CityId: 59450,
                            CityName: "Vancouver"
                        }
                    },
                    PostalCode: {
                        type: "string"
                    },
                    AddressText: {
                        type: "string"
                    },
                    IsMainAddress: {
                        type: "boolean"
                    },
                    AddressId: {
                        type: "integer"
                    }
                }
            }

        },
        pageSize: 3,
    },
    ignoreCase: true,
    height: 250,
    filterable: true,
    sortable: true,
    pageable: true,
    reorderable: false,
    groupable: false,
    batch: true,
    navigatable: true,
    toolbar: ["create", "save", "cancel"],
    editable: true,
    columns: [{
        field: "AddressType",
        title: "Type",
        editor: AddressTypeDropDownEditor,
        template: "#=AddressType.AddressTypeName#",
    }, {
        field: "Country",
        title: "Country",
        editor: CountryDropDownEditor,
        template: "#=Country.CountryName#",
    }, {
        field: "State",
        title: "State",
        editor: StateDropDownEditor,
        template: "#=State.StateName#",
    }, {
        field: "City",
        title: "City",
        editor: CityTypeDropDownEditor,
        template: "#=City.CityName#",
    }, {
        field: "PostalCode",
        title: "Postal Code",
    }, {
        field: "AddressText",
        title: "Address",
    }, {
        field: "IsMainAddress",
        title: "Main?",
        width: 65,
        template: function (e) {
            if (e.IsMainAddress == true) {
                return '<img align="center" src ="images/check-icon.png" />';
            } else {
                return '';
            }
        }
        // hidden: true

    }, {
        command: "destroy",
        title: "&nbsp;",
        width: 90
    },

    ]
});

问题是当我尝试按国家或州或城市过滤时出现错误

TypeError: "".toLowerCase 不是函数

我尝试将 Country 的类型更改为字符串,我使用comobox,因此值未定义。我还尝试将类型更改为对象,值显示正确但我无法过滤。我得到了同样的错误(toLowerCase)

我怎样才能解决这个问题 ??

我的网格与这个例子非常相似

这是jsFiddle。我刚刚添加了过滤器。我仍然得到以前的错误

我想过滤类别,有什么帮助吗?

4

1 回答 1

3

这是您过滤数据源的方式Kendo dataSource , filter

所以获取网格的数据源,

var gridDatasource = $("#address-grid").data('kendoGrid').dataSource;

并像这个例子一样过滤它。

gridDatasource.filter({ ... });

如果您提供一个有效的 jsFiddle,您可能会得到更具体的答案。

具体答案:

您添加了过滤器,因此对于 Category 它不起作用,因为正如我所说,它是可观察的,而不是您可以过滤为字符串的文件。

因此,您必须为此列指定更好的过滤器,如下所示:

field: "Category",
title: "Category",
width: "160px",
editor: categoryDropDownEditor,
template: "#=Category.CategoryName#",
filterable: {
    extra: false,
    field:"Category.CategoryName",
    operators: {
        string: {
            startswith: "Starts with",
            eq: "Is equal to",
            neq: "Is not equal to"
        }
    }
}

看到这个 jsFiddle --> http://jsfiddle.net/blackjim/Sbb5Z/463/

于 2013-06-24T19:03:39.743 回答