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

Grid column menu filter settings

2 Answers 607 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ernestas
Top achievements
Rank 1
Ernestas asked on 12 Nov 2014, 02:21 PM
I want my grid column menu filters to have default operands based on the column type: for dates gte and lte, for texts contains etc. I have tried to do this by following the example in http://demos.telerik.com/kendo-ui/grid/filter-menu-customization, however it seems the operands tend to switch to default operand eq - first one in the dropdown list - if a value to filter by is not picked and applied.

var columnMenu = function(e) {
        var $filterMenu = e.container.find(".k-filter-menu");
        var $firstValueDropDown = $filterMenu.find("select:eq(0)");
        var firstValueDropDown = $firstValueDropDown.data("kendoDropDownList");
        if (!firstValueDropDown.dataSource.view().length) {
            $firstValueDropDown.closest(".k-widget").hide();
        }
        if (($filterMenu.find(".k-datepicker").length) || ($filterMenu.find(".k-datetimepicker").length)) {
            firstValueDropDown.value("gte");
            firstValueDropDown.trigger("change");
 
            var logicDropDown = $filterMenu.find("select:eq(1)").data("kendoDropDownList");
            logicDropDown.value("and");
            logicDropDown.trigger("change");
 
            var secondValueDropDown = $filterMenu.find("select:eq(2)").data("kendoDropDownList");
            secondValueDropDown.value("lte");
            secondValueDropDown.trigger("change");
        }
     };

2 Answers, 1 is accepted

Sort by
0
Ernestas
Top achievements
Rank 1
answered on 12 Nov 2014, 02:26 PM
This forum does not allow editing posts, url of original example I followed is actually http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#events-filterMenuInit
0
Accepted
Alexander Popov
Telerik team
answered on 14 Nov 2014, 01:42 PM
Hello Dovydas,

In the current scenario I would suggest using the columnMenuInit event to get the instance of the respective FilterMenu. For example:
$("#grid").kendoGrid({
  columnMenuInit: function(e){
    var filterMenu = e.container.find("[data-role='filtermenu']").getKendoFilterMenu();
    filterMenu.popup.bind("open", function() {
      alert("Set operators here")
    });
  }...

That would allow you to bind to the "open" event of the FilterMenu's Popup, which is triggered each time the ColumnMenu is opened and would help you set the filter operators.

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