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

Set an initial filter in a grid

8 Answers 634 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 1
Phil asked on 16 Jan 2013, 03:40 PM
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)?

8 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 18 Jan 2013, 07:48 AM
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!
0
Phil
Top achievements
Rank 1
answered on 19 Jan 2013, 05:49 AM
Thanks for the example Rosen, That did the trick.
0
Darron
Top achievements
Rank 1
answered on 15 Sep 2016, 07:38 PM

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?

0
Rosen
Telerik team
answered on 16 Sep 2016, 07:30 AM

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
0
Darron
Top achievements
Rank 1
answered on 16 Sep 2016, 12:52 PM

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?

0
Rosen
Telerik team
answered on 17 Sep 2016, 07:19 AM

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
0
Mike
Top achievements
Rank 1
answered on 12 May 2017, 08:38 AM

thanks for the video - after hours of searching of this functionallity - finally.

 

but here a furtheron question on this.

how to do AND - OR conditions in this way?

thanks

0
Boyan Dimitrov
Telerik team
answered on 16 May 2017, 07:34 AM

Hello Alain,

The filter.logic contains the logic whether filter values should be evaluated as "AND" or "OR". 

Regards,
Boyan Dimitrov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Phil
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Phil
Top achievements
Rank 1
Darron
Top achievements
Rank 1
Mike
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or