This is a migrated thread and some comments may be shown as answers.

Combine new filters with active filters

1 Answer 52 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 15 Apr 2014, 07:42 AM
Hello,

I'm using a multiselect filter for the one of my columns. Also I want to maintain the active filters so you can further narrow down the result.
For now i'm trying to do this as below but the OldFilters variable is empty.

                    function areaOfStudyFilter(element)
        {
            //mvvm binding should be removed, other way the dataSource will try to update the UI when the dataSource filter has changed
            element.removeAttr("data-bind");
            var dataSource = $("#Grid").data("kendoGrid").dataSource
            element.kendoMultiSelect({
                optionLabel: "-Selecteer waarde-",
                dataSource:
                    {
                        transport: {
                            read: "@Url.Action("Filter_AreaOfStudyDescriptions")"
                        }
                    },
                change: function (e) {
                    var oldFilters = dataSource.filter();
                    var filter = {logic:"and", filters:[]}
                    var newFilter = { logic: "or", filters: [] };
                    var values = this.value();
                    if (values.length == 0)
                    {
                        dataSource.filter({ field: "AreaOfStudy", operator: "startswith", value: "" })
                        oldFilters = dataSource.filter();
                    }

                    $.each(values, function (i, v) {
                        newFilter.filters.push({ field: "AreaOfStudy", operator: "eq", value: v });
                        dataSource.filter({ field: "AreaOfStudy", operator: "startswith", value: "" })
                        oldFilters = dataSource.filter();
                    });
                    filter.filters.push(newFilter);
                    filter.filters.push(oldFilters);
                    dataSource.filter(filter);
                }
            });
        }

Kind Regards,

Tim

1 Answer, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 16 Apr 2014, 03:58 PM
Hello Tim,

From the provided code sample I am not able to tell you exactly what is causing this behavior. Would it be possible to provide a runnable sample that we can debug and see what exactly happens? 

Thank you in advance for this.

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Tim
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Share this question
or