-
Notifications
You must be signed in to change notification settings - Fork 79
Added new kb article grid-highlight-filter-icon #2481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
xristianstefanov
merged 2 commits into
master
from
new-kb-grid-highlight-filter-icon-efc8356dd1104ffebf009b780be800f7
Nov 1, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| --- | ||
| title: Filter Icon Not Highlighted | ||
| description: This article demonstrates how to fix the filter menu icon not being highlighted when filters are applied programmatically. | ||
| type: troubleshooting | ||
| page_title: How to Highlight Filter Icon in a Blazor Grid with Pre-applied Filters | ||
| slug: grid-highlight-filter-icon | ||
| tags: grid, blazor, filter, highlight, initialization, compositefilterdescriptor | ||
| res_type: kb | ||
| ticketid: 1668133 | ||
| --- | ||
|
|
||
| ## Environment | ||
|
|
||
| <table> | ||
| <tbody> | ||
| <tr> | ||
| <td>Product</td> | ||
| <td>Grid for Blazor</td> | ||
| <td>TreeList for Blazor</td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
|
|
||
| ## Description | ||
|
|
||
| When using the TelerikGrid for Blazor, applying a filter programmatically on initialization does not highlight the header filter icon. This behavior is expected when filters are manually applied by the user, indicating which columns are currently filtered. | ||
|
|
||
| ## Cause | ||
|
|
||
| The issue arises due to the direct use of `FilterDescriptor` without wrapping it in a `CompositeFilterDescriptor`. The `CompositeFilterDescriptor` is necessary to group individual filters and ensure the UI reflects the applied filters correctly. | ||
|
|
||
| ## Solution | ||
|
|
||
| To highlight the filter menu icon upon initialization, wrap the filter definitions in a `CompositeFilterDescriptor`. This approach ensures the Grid's UI accurately displays which filters are active. | ||
|
|
||
| Below is an example demonstrating how to initialize a Grid with a predefined filter on the "Released" column that highlights the filter icon correctly: | ||
|
|
||
| ```RAZOR | ||
| @using Telerik.DataSource | ||
|
|
||
| <TelerikGrid Data="@GridData" | ||
| Pageable="true" | ||
| PageSize="5" | ||
| Sortable="true" | ||
| FilterMode="@GridFilterMode.FilterMenu" | ||
| Groupable="true" | ||
| OnStateInit="@( (GridStateEventArgs<Product> args) => OnGridStateInit(args) )"> | ||
| <GridColumns> | ||
| <GridColumn Field="@nameof(Product.Name)" /> | ||
| <GridColumn Field="@nameof(Product.Released)" /> | ||
| <GridColumn Field="@nameof(Product.Discontinued)" /> | ||
| </GridColumns> | ||
| </TelerikGrid> | ||
|
|
||
| @code { | ||
| private List<Product> GridData { get; set; } | ||
|
|
||
| private async Task OnGridStateInit(GridStateEventArgs<Product> args) | ||
| { | ||
| var discontinuedColumnFilter = new CompositeFilterDescriptor() | ||
| { | ||
| FilterDescriptors = new FilterDescriptorCollection() { | ||
| new FilterDescriptor() | ||
| { | ||
| Member = "Released", | ||
| Operator = FilterOperator.IsLessThan, | ||
| Value = DateTime.Today, | ||
| MemberType = typeof(DateTime) | ||
| } | ||
| } | ||
| }; | ||
| args.GridState.FilterDescriptors.Add(discontinuedColumnFilter); | ||
| } | ||
|
|
||
| protected override void OnInitialized() | ||
| { | ||
| GridData = new List<Product>(); | ||
| var rnd = new Random(); | ||
|
|
||
| for (int i = 1; i <= 12; i++) | ||
| { | ||
| GridData.Add(new Product() | ||
| { | ||
| Id = i, | ||
| Name = $"Product {i}", | ||
| Released = DateTime.Now.AddDays(-rnd.Next(1, 365)).AddYears(-rnd.Next(1, 10)).Date, | ||
| Discontinued = i % 3 == 0 | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| public class Product | ||
| { | ||
| public int Id { get; set; } | ||
| public string Name { get; set; } | ||
| public DateTime Released { get; set; } | ||
| public bool Discontinued { get; set; } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## See Also | ||
|
|
||
| - [Grid Overview](https://docs.telerik.com/blazor-ui/components/grid/overview) | ||
| - [Grid OnStateInit Event](https://docs.telerik.com/blazor-ui/components/grid/state#onstateinit) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.