One filter for two datasource fileds

2 posts, 0 answers
  1. Tomasz
    Tomasz avatar
    18 posts
    Member since:
    May 2017

    Posted 03 Sep 2020 Link to this post

    Hello,

    I have a grid with client template that holds two values from datasource. Is it possible to filter this two fileds at once using one filter menu (e.g adding secondary filter on the fly when bounded column is filtered)?

  2. Nikolay
    Admin
    Nikolay  avatar
    301 posts

    Posted 08 Sep 2020 Link to this post

    Hello Tomasz,

    I could suggest applying a custom filter in columns.filterable.ui handler where the desired column fields can be included in the filter of the current one. For example:

    columns.Bound(e => e.City)
                    .ClientTemplate("#=FirstName# #=LastName#")
                    .Filterable(filterable => filterable.UI("nameFilter"))
                    .Width(200);
    ..
    function nameFilter(element) {
              var textbox = element.kendoTextBox({
                change: function(e) {
                  var value = e.sender.value();
                  var dataSource = $("#grid").data("kendoGrid").dataSource;
                  var filter = { logic: "or", filters: [] };
                  filter.filters.push({ field: "FirstName", operator: "eq", value: value }, { field: "LastName", operator: "eq", value: value });
                  if (value) {
                    dataSource.filter(filter);
                  }
                  else {
                    dataSource.filter({});
                  }
                }
              })
              }

    Please find a runnable demo demonstrating the above in the following link:

    Let me know fi you have any questions.

    Regards,
    Nikolay
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Back to Top