Custom filter, FilterMenuInit fired only once

7 posts, 1 answers
  1. Rafael
    Rafael avatar
    4 posts
    Member since:
    May 2013

    Posted 18 Dec 2014 Link to this post

    Hello

    I have tried successfully to create a grid filter with preset options by using FilterMenuInit() and it works fine at the first time.
    However, I noticed that function is only called once, but the filter options are reset after some value is applied or the filter is cleared.

    In order to reproduce this behavior, the sample from this thread may be used: http://www.telerik.com/forums/how-to-define-a-kendo-grid-column-filter-between-two-dates
    at http://dojo.telerik.com/@pesho/UMIw/3

    In that sample, click on the filter for "Order Date". In the first run, it will display options for gte and lte. Then, simply click on Clear and fire it up again. Now, both filters are set to the option "Is equal to".

    Is there any way to work around that issue without also binding to the button actions in the Filter?

    Regads,
    Rafael
  2. Answer
    Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 22 Dec 2014 Link to this post

    Hello Rafael,

    I can suggest the following workaround:

    $scope.filterInit = function (e) {
      e.container.data("kendoPopup").bind("open", function() { //bind to the open of the filter menu popup
        alert('the type is -> ' + e.sender.dataSource.options.schema.model.fields[e.field].type);
        if (e.field == "OrderDate") {
          var beginOperator = e.container.find("[data-role=dropdownlist]:eq(0)").data("kendoDropDownList");
          beginOperator.value("gte");
          beginOperator.trigger("change");
     
          var endOperator = e.container.find("[data-role=dropdownlist]:eq(2)").data("kendoDropDownList");
          endOperator.value("lte");
          endOperator.trigger("change");
        }
      });
    };


    For your convenience I updated the Kendo Dojo sample: http://dojo.telerik.com/@valchev/iZoXe

    Regards,
    Alexander Valchev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. Rafael
    Rafael avatar
    4 posts
    Member since:
    May 2013

    Posted 22 Dec 2014 in reply to Alexander Valchev Link to this post

    Thanks Alexander, that works just fine.
  5. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 22 Dec 2014 Link to this post

    Hi Rafael,

    I am glad to hear that the approach suits in your case. Just a little follow up - for performance optimization you may move the "if" clause outside of the bind event handler:

    $scope.filterInit = function (e) {
      alert('the type is -> ' + e.sender.dataSource.options.schema.model.fields[e.field].type);
      if (e.field == "OrderDate") {
     
        e.container.data("kendoPopup").bind("open", function() {
          var beginOperator = e.container.find("[data-role=dropdownlist]:eq(0)").data("kendoDropDownList");
          beginOperator.value("gte");
          beginOperator.trigger("change");
     
          var endOperator = e.container.find("[data-role=dropdownlist]:eq(2)").data("kendoDropDownList");
          endOperator.value("lte");
          endOperator.trigger("change");
        });
     
      }
    };


    In this way you will bind to the open event of the OrderDate filter menu only. With the previous approach you are binding the open event of all filter menu popups and are checking inside the event handler if the field is the one you need.

    Regards,
    Alexander Valchev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  6. Chandra
    Chandra avatar
    2 posts
    Member since:
    Jul 2016

    Posted 12 Aug in reply to Alexander Valchev Link to this post

    Hi,

    I have a similar situation as OP and I am using the similar code.

    There is another bug with the  suggested fix . When I select some date in the 'lte' datepicker (second picker) and hit submit.

    Next time when I open the filter, the selected date appears in the first datepicker.

    The issue can be replicated in the Dojo sample Alexander gave

    http://dojo.telerik.com/@valchev/iZoXe

    How do I fix it? Thanks

  7. Chandra
    Chandra avatar
    2 posts
    Member since:
    Jul 2016

    Posted 12 Aug in reply to Chandra Link to this post

    Update to my earlier question.

    Looks like that is the behavior in all the filter controls, not just the custom ones.

    Is there any fix for that? Where the earlier search appears in the correct control?

    Thanks

  8. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 16 Aug Link to this post

    Hello Chandra,

    This thread is very old. The example that you reference uses outdated Kendo UI version.
    Please upgrade your project to the latest release and let me know if the issue still persists.

    Regards,
    Alexander Valchev
    Telerik by Progress
     
    Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
     
Back to Top
Kendo UI is VS 2017 Ready