KendoUI网格过滤器发布两次

时间:2015-11-20 22:28:05

标签: kendo-ui kendo-grid

我的网格带有自定义多选滤镜。当我单击过滤器图标时,AJAX方法调用API来获取过滤器值。方法调用在DocType列中定义。

这是我的网格构建器功能:

 $("#attachmentsGrid").kendoGrid({
            pageable: {
                change: function() {
                    CH.RelatedItems.GridPager();
                }
            },
            scrollable: false,
            sortable: true,
            dataSource: attachments,
            filterable: {
                extra: false,
                operators: {
                    string: {
                        startswith: "Starts with",
                        eq: "Is equal to",
                        neq: "Is not equal to",
                        contains: "Contains",
                    }
                }
            },
            columns:
            [
                {
                    title: "id",
                    field: "Id",  //turns out this needs to be lower case
                    sortable: false,
                    filterable: false,
                    template: "<input name='cbCheckboxColumn' type='checkbox' onclick='CH.RelatedItems.ToggleAttachmentsByCheckboxColumn()' data-row='#: Id#' />",
                    headerTemplate: "<input id='cbCheckboxHeader' type='checkbox' onclick='CH.RelatedItems.ToggleAttachmentsByCheckboxHeader()'",
                    width: "18px",
                },
                {
                    title: "Exists?",
                    field: "IsAlreadyAttached",
                    type: "boolean",
                    sortable: false,
                    template: "<div style='text-align: center'>#: IsAlreadyAttached #</div>",
                    filterable: false,
                    width: "110px",
                },
                {
                    title: "Icon",
                    field: "DocType",
                    sortable: true,
                    template: "<div style='text-align: center'><img src='" + config.SPHostUrl + "/_layouts/images/#: DocIcon #' /></div>",
                    width: "60px",
                    filterable: { 
                        ui: CH.RelatedItems.AttachmentsIconFilter,
                        extra: false,
                    },
                },
                {
                    title: "File Name",
                    field: "Name",
                    sortable: true,
                    filterable: false,
                    template: "<a href='#: Url#' target='_blank'>#: Name#</a>",
                    width: "650px",
                },
                {
                    title: "Modified",
                    field: "LastModifiedDateOnly",
                    template: "<span>#: LastModified#</span>",
                    sortable: true,
                    width: "250px",
                    filterable: {
                        ui: CH.RelatedItems.AttachmentsDateFilter,
                        extra: false
                    }
                },
            ],
            dataBound: CH.RelatedItems.PostGridDataBound
        });

AttachmentsIconFilter函数在这里:

pub.AttachmentsIconFilter = function (element) {
        var menu = $(element).parent();
        menu.find(".k-filter-help-text").text("Show document types:");
        menu.find("[data-role=dropdownlist]").remove();

        var multiSelect = element.kendoMultiSelect({ 
            dataSource: { 
                transport: {
                    read: { 
                        datatype: "jsonp",
                        url: config.WorkPaperViewRelativePath + "/_RelatedItemsPopup/GetAttachmentsUniqueDocIcons/" + config.SPQueryString
                    }
                }
            },
        }).data("kendoMultiSelect");
        menu.find("[type=submit]").on("click", { widget: multiSelect }, CH.RelatedItems.AttachmentsFilterByIcon);
    }

当AttachmentsIconFilter运行时,AJAX调用会进行两次:

Kendo Double GET

我认为属性:filter:{extra:false}应该阻止这个双GET?

此外,当我选择我的过滤器并且网格发出新请求以获取过滤后的记录时,它会执行双重POST。过滤网格的调用函数如下:

pub.AttachmentsFilterByIcon = function (e) {
        var icons = e.data.widget.value();
        var filter = { logic: "or", filters: [] };
        for (var i = 0; i < icons.length; i++)
        {
            filter.filters.push({ field: "DocIcon", operator: "Contains", value: icons[i].Contains });
        }
        $("#attachmentsGrid").data("kendoGrid").dataSource.filter(filter);
    }

这里有什么帮助吗?我错过了什么?

0 个答案:

没有答案