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

[Solved] Column Filterable UI property

1 Answer 220 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeremy
Top achievements
Rank 1
Jeremy asked on 24 Oct 2014, 03:59 PM
I have a question about the Column.Filterable.UI property.  I have been experimenting with custom filtering by following this example http://dojo.telerik.com/EyoL/31, however it appears that the UI function only gets called once.  Is this correct?  What I am trying to do is limit the values displayed based on other filters applied.  Below is a sample of my function.
01.function createMultiSelect(element, fieldName) {
02.            var isFilter = $("#grid").data("kendoGrid").dataSource.filter();
03.            var data = $("#grid").data("kendoGrid").dataSource;
04.            var ds = data.data();
05.            if (isFilter) {
06.                var query = new kendo.data.Query(ds);
07.                ds = query.filter(isFilter).data;
08.            }
09.            else {
10.                ds = data.data();
11.            }
12.            //var names = ds.sortBy(ds.uniq(ds.pluck(ds, "GroupCode")), function (n) { return n; });
13.            var names = _.sortBy(_.uniq(_.pluck(ds, fieldName)), function (n) { return n; });
14.            //mvvm binding should be removed, other way the dataSource will try to update the UI when the dataSource filter has changed
15.            element.removeAttr("data-bind");
16. 
17.            element.kendoMultiSelect({
18.                dataSource: names,
19.                change: function (e) {
20.                    var curFilter
21.                    if (isFilter) {
22.                        curFilter = data.filter().filters;
23.                    }
24.                    else {
25.                        curFilter = [];
26.                    }
27.                    var filter = { logic: "or", filters: curFilter };
28.                    var values = this.value();
29.                    $.each(values, function (i, v) {
30.                        filter.filters.push({ field: fieldName, operator: "eq", value: v });
31.                    });
32.                    console.log(this.dataSource.data());
33.                    $("#grid").data("kendoGrid").dataSource.filter(filter);
34.                }
35.            });
36.        }

1 Answer, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 28 Oct 2014, 01:28 PM
Hi Jeremy,

Indeed, this code is executed once and this is the expected behavior. It is designed to initialize the widget in the filter menu and there is no reason to do that multiple times. In this case I would suggest subscribing to the open event of the filter menu's popup. For example: 
var grid = $("#grid").kendoGrid({
  //use the filterMenuInit event to get the instance of the popup
  filterMenuInit: function(e){
    e.container.getKendoPopup().bind("open", function() {
        alert("opening filter menu for " + e.field);
    })
  },

Regards,
Alexander Popov
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
Jeremy
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Share this question
or