Set an initial filter in a grid

7 posts, 1 answers
  1. Phil
    Phil avatar
    6 posts
    Member since:
    Jan 2013

    Posted 16 Jan 2013 Link to this post

    Using the KendoUI ASP.NET MVC Grid, it is possible to create a filter in the DataSource property so that on the initial load of the grid, it only displays the filtered records. However, when using this method to create an initial filter on the data source, it does just that, actually filters the data source completely. it does not allow the end user to click the filter button, display the current filter criteria, click clear, and create a new filter to include some of the data that was not initially filtered out. This is because the data source is filtered.

    In a grid, is there a way of setting an initial filter when the grid loads so that when the end user is clicks on the filter button, they will see the contents of the initial filter (for example "Hanari Carnes" - see step1...png), and can clear the filter to display all of the data (step2...png)?
  2. Answer
    Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 18 Jan 2013 Link to this post

    Hi Phil,

    The default behavior is to show the initial filters within the Grid's filter menu. Please, take a look at this short video which captures the behavior, maybe I'm missing something obvious.

    Regards,
    Rosen
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Phil
    Phil avatar
    6 posts
    Member since:
    Jan 2013

    Posted 18 Jan 2013 Link to this post

    Thanks for the example Rosen, That did the trick.
  5. Darron
    Darron avatar
    2 posts
    Member since:
    Jul 2016

    Posted 15 Sep in reply to Rosen Link to this post

    Adding .Filter(f => f.Add(p => p.WBS).StartsWith("BR549")) does indeed apply that filter to the grid right from the start.

    But after a user clears that programmed initial filter, it seems to corrupt the operation of the filters from then on.  "Clear" filter removes it from the filter menu, but does not update the result set.  Changing the filter may or may not update the result set.  Is this a known bug and is there a recommended fix?

  6. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 16 Sep Link to this post

    Hello Darron,

    I'm not able to observe such behavior locally. Please provide a sample project which to demonstrates the issue in question.

    Regards,
    Rosen
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  7. Darron
    Darron avatar
    2 posts
    Member since:
    Jul 2016

    Posted 16 Sep in reply to Rosen Link to this post

    The problem was due to the size of the dataset, too many lines returned to the grid.

    If paging is turned off, and too many lines are requested, the grid will show as if empty.

    If an initial filter reduces the set to a size the grid can show without paging, then changing the filter to include additional lines can cause it to exceed the limit, which causes the filter to show changed, but the results to stay with the results of the previous filter.

    The problem is due to the grid's size limitations, and solvable using paging, which I wanted to avoid.

    But paging is probably the quickest way to avoid the potential for failure due to volume.

    On another note, I wanted to use the "Columns Menu" but noticed that its use hides the filter icon's highlighting that should show when a filter has been applied.

    Is there an easy way to add an "As Filtered" description to the footer?

  8. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 17 Sep Link to this post

    Hello Darron,

    The paging behavior you have described is most probably due to the response hitting the JavaScriptSerializer max response length limit. This is discussed here.

    I'm not sure what you mean by "As Filtered". However, if you want to show inside the footer template information if the current column is filtered. You could do this using similar to the following JavaScript functions:

    function hasFilter(fieldName) {
       var filter = $("#grid").getKendoGrid().dataSource.filter();           
     
       if (filter) {             
         filter = filter.filters || [filter];
     
         var matcher = function(filter) {
           if (filter.filters) {
             return $.grep(filter.filters, matcher).length > 0;
           }
           return filter.field === fieldName;
         };
     
         return $.grep(filter, matcher).length > 0;
       }
       return false;
     }
     
     function footerTemplate(columnName) {             
       return function() {                               
         return hasFilter(columnName) ? "filtered" : "";
       }
     }

    Which can be used in the column definition such as -> footerTemplate: footerTemplate("ShipCity") // where the ShipCity is the data field.

    Also if you continue to experience difficulties I would suggest to open a separate support request as the topic diverge from the original thread's discussion.

    Regards,
    Rosen
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET MVC is VS 2017 Ready