Also, in my application, I anticipate up to 500K rows (when there is no filter), and approximately 50-75 columns (most hidden at any given time). Do you anticipate any performance challenges with this many rows and columns with the new RadGridView?
6 Answers, 1 is accepted
You can set the filter in the code behind by using FieldFilterDescription and CompositeFilterDescription.
You have to set one of them to RadGridView FilterDescription property.
FieldFilterDescription has 2 properties:
- FieldName - the name of the property
- Values - collection of values that are filtered
Sample code follows:
<telerik:RadGridView Name="radGridView1" AutoGenerateColumns="True" Height="500" /> |
public partial class Page : UserControl |
{ |
public Page() |
{ |
InitializeComponent(); |
this.radGridView1.ItemsSource = this.GetPersons(); |
FieldFilterDescription filterDescriptionAge = new FieldFilterDescription(); |
filterDescriptionAge.FieldName = "Age"; |
filterDescriptionAge.Values.Add(1); |
FieldFilterDescription filterDescriptionName = new FieldFilterDescription(); |
filterDescriptionName.FieldName = "Name"; |
filterDescriptionName.Values.Add("10"); |
CompositeFilterDescription compositeFilterDescription = new CompositeFilterDescription(); |
compositeFilterDescription.FilterDescriptions.Add(filterDescriptionAge); |
compositeFilterDescription.FilterDescriptions.Add(filterDescriptionName); |
this.radGridView1.FilterDescription = compositeFilterDescription; |
} |
public IEnumerable<Person> GetPersons() |
{ |
return from i in Enumerable.Range(1, 200) |
select new Person { Name = (i / 10).ToString(), Age = i % 10 }; |
} |
} |
public class Person |
{ |
public string Name { get; set; } |
public int Age { get; set; } |
} |
You can also create your custom field description class. You have to inherit base FilterDescription class.
You will have performance issues with so many rows and columns. It will be much better if you consider implementing some kind of paging.
Look at this blog post.
All the best,
Jordan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
1. There is a column in the RadGridView named "Category"
2. I want to filter for all values of Category equal to "ABC" or "DEF"
I tried the following, but it does not work:
private void PageLoaded(object sender, RoutedEventArgs e) |
{ |
FieldFilterDescription filterDescriptionCategory = new FieldFilterDescription(); |
filterDescriptionCategory.FieldName = "Category"; |
FilterDescriptor filterDescriptorABC = new FilterDescriptor("Category", FilterOperator.IsEqualTo, "ABC"); |
filterDescriptionCategory.DistinctValues.Add(filterDescriptorABC); |
FilterDescriptor filterDescriptorDEF = new FilterDescriptor("Category", FilterOperator.IsEqualTo, "DEF"); |
filterDescriptionCategory.DistinctValues.Add(filterDescriptorDEF); |
this.radGridView1.FilterDescription = filterDescriptionCategory; |
} |
The ItemsSource for radGridView1 was set before the PageLoaded() method was called, and was set to an ObserveableCollection. My grid shows all of the rows, as opposed to only those with values of "ABC" or "DEF". I.e., no filtering is being performed.
Hello GEB,
The proper code is:
private void PageLoaded(object sender, RoutedEventArgs e)
{
FieldFilterDescription filterDescriptionCategory = new FieldFilterDescription();
filterDescriptionCategory.FieldName = "Category";
filterDescriptionCategory.DistinctValues.Add(new FilterDescriptor("Category", FilterOperator.IsEqualTo, "ABC"));
filterDescriptionCategory.DistinctValues.Add(new FilterDescriptor("Category", FilterOperator.IsEqualTo, "DEF"));
// Apply distinct filter
filterDescriptionCategory.SelectedValues.Add(filterDescriptionCategory.DistinctValues[0]);
this.radGridView1.FilterDescription = filterDescriptionCategory;
}
The new FieldFilterDescription class is a composite filter, that has the ability to filter depending on several parameters:
DistinctValues is the collection that is used to populate the checkbox list in the filtering dropdown
SelectedValues is the collection, containing the checked items from the above list. It is the actual filter.
Filter1 is the first filter, below the checkbox list
Filter2 is the second filter.
If you want to display many predefined items, you should use the SelectedValues. Otherwise, I would recommend using Filter1 and Filter2, e.g. the code above would be:
FieldFilterDescription filterDescriptionCategory = new FieldFilterDescription();
filterDescriptionCategory.FieldName = "Category";
filterDescriptionCategory.Filter1.Operator = FilterOperator.IsEqualTo;
filterDescriptionCategory.Filter1.Value = "ABC";
this.radGridView1.FilterDescription = filterDescriptionCategory;
Greetings,
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
filterDescriptionCategory.DataType =
typeof(String);
Otherwise, I would get a null reference when I tried to apply the filter to the grid. Secondly, your example successfully filters for "ABC", but none of the rows where the Category is "DEF" are displayed. It seems to have filtered for the first value, but not for the second. I'm looking for a filter that essentially displays the row if they are "ABC" or "DEF".
filterDescriptionCategory.SelectedValues.Add(filterDescriptionCategory.DistinctValues[1]);
to add the second filter to the SelectedValues, then no filtering is applied and all categories are shown in the grid. So, using this example code, it appears as though I can show use one of the filtered values, but not both.
Note that in my application, there are times where I might want to apply 10 or more filtering values to a single column. For example, I might want to find "ABC" or "DEF" or "GHI" ... So Filter1 and Filter2 that you referred to will not wor in my case.
The distinct filters should do the job. However, there is a small optimization in the filter logic, that does not apply the filter if the SelectedValues collection is the same as DistinctValues collection (this is when you select all checkboxes in the UI, which contain ALL values in the column). So to resolve the problem I would recommend either adding a dummy value in the DistinctValues, or add all distinct values from the column in that collection.
Greetings,
Valeri Hristov
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.