-
Notifications
You must be signed in to change notification settings - Fork 79
docs(common):Create common article for descriptors #2416
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
Merged
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
7c9548b
docs(common):Create common article for descriptors
NansiYancheva 0049a35
Update components/gantt/gantt-tree/filter/overview.md
NansiYancheva 995d049
revamp by adding all descriptors
NansiYancheva 3eab836
revamp main and refer related articles
NansiYancheva 7a4d238
update common article
NansiYancheva 5308b44
Update common-features/data-binding/descriptors.md
NansiYancheva 1aa3130
Update common-features/data-binding/descriptors.md
NansiYancheva de0bd4d
Update common-features/data-binding/descriptors.md
NansiYancheva 990e0ed
Update common-features/data-binding/descriptors.md
NansiYancheva 00ffc44
Update common-features/data-binding/descriptors.md
NansiYancheva 718ae0d
Update components/filter/overview.md
NansiYancheva c6b287e
update after review
NansiYancheva 754fe04
update after support review
NansiYancheva efa5736
Update common-features/data-binding/descriptors.md
NansiYancheva ae7ed26
Update common-features/data-binding/descriptors.md
NansiYancheva 1065253
Update common-features/data-binding/descriptors.md
NansiYancheva dfcd925
Update common-features/data-binding/descriptors.md
NansiYancheva 94fa2e2
Update common-features/data-binding/descriptors.md
NansiYancheva ca6a715
Update common-features/data-binding/descriptors.md
NansiYancheva 0352538
Update common-features/data-binding/descriptors.md
NansiYancheva 58ba27c
Update common-features/data-binding/descriptors.md
NansiYancheva 5844650
Update common-features/data-binding/descriptors.md
NansiYancheva 6db2252
Update common-features/data-binding/descriptors.md
NansiYancheva 7caa380
Update common-features/data-binding/descriptors.md
NansiYancheva 0e3247b
update after tech writer review
NansiYancheva 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
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,317 @@ | ||
| --- | ||
| title: Descriptors - FilterDescriptor, SearchFilter, SortDescriptor, GroupDescriptor | ||
| page_title: Descriptors - FilterDescriptor, SearchFilter, SortDescriptor, GroupDescriptor | ||
| description: Discover the FilterDescriptor, SortDescriptor, SearchFilter and GroupDescriptor properties and how to access their values. | ||
| slug: common-features-descriptors | ||
| tags: telerik,blazor,filterdescriptor, sortdescriptor, groupdescriptor, searchfilter | ||
| published: True | ||
| position: 10 | ||
| --- | ||
|
|
||
|
|
||
| ## Components with Descriptors | ||
|
|
||
| This article explains how to retrieve the applied filtering, searching, sorting, and grouping criteria in Blazor components. The article applies to components that support these features. The components that offer one or all of the functionalities are: | ||
| * The [Filter]({%slug filter-overview%}) | ||
| * The [Gantt]({%slug gantt-overview%}) | ||
| * The [TreeList]({%slug treelist-overview%}) | ||
| * All components that [expose the `OnRead` event]({%slug common-features-data-binding-onread%}#components-with-onread-event), excluding the [ListView]({%slug listview-overview%}), because the ListView doesn't support built-in filtering, searching, sorting, and grouping. | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Obtain Filtering, Searching, Sorting, Grouping criteria | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| There are two ways to obtain the applied filtering, searching, sorting, grouping criteria: | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #### Through the OnRead Event | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Use the [`Request` property]({%slug common-features-data-binding-onread%}#event-argument) of the [`OnRead` event argument object](/blazor-ui/api/Telerik.Blazor.Components.ReadEventArgs): | ||
|
|
||
| ````CS | ||
| async Task OnReadHandler(...ReadEventArgs args) | ||
| { | ||
| // Get the applied filtering and searching criteria | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // args.Request.Filters | ||
| // Get the applied grouping criteria, including: | ||
| // *the field by which the user groups | ||
| // *the sort direction of the groups ordering | ||
| // args.Request.Groups | ||
| // Get the applied sorting criteria, including: | ||
| // *the field which the user sorts | ||
| // *the sort direction | ||
| // args.Request.Sorts | ||
| } | ||
| ```` | ||
|
|
||
| #### Through the Component State | ||
| Use the component state property of the `OnStateChanged` event argument. For example: | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ````CS | ||
| async Task OnStateChangedHandler(GridStateEventArgs<Product> args) | ||
| { | ||
| // Get the applied filtering criteria | ||
| // args.GridState.FilterDescriptors | ||
| // Get the applied searching criteria | ||
| // args.GridState.SearchFilter | ||
| // Get the applied grouping criteria, including: | ||
| // *the field by which the user groups | ||
| // *the sort direction of the groups ordering | ||
| // args.GridState.GroupDescriptors | ||
| // Get the applied sorting criteria, including: | ||
| // *the field which the user sorts | ||
| // *the sort direction | ||
| // args.GridState.SortDescriptors | ||
| } | ||
| ```` | ||
|
|
||
| At the bottom of the article you will find full examples. | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| ## Filtering | ||
|
|
||
| The filtering criteria for each filtered field is stored in an individual collection of [`IFilterDescriptor`](/blazor-ui/api/Telerik.DataSource.IFilterDescriptor). To access the filtering criteria, such as the user input to filter by, cast each `IFilterDescriptor`: | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| * If the component is of type input or select, such as the AutoComplete, the ComboBox, the DropDownList, the MultiColumnComboBox, the MultiSelect, cast each `IFilterDescriptor` to [`FilterDescriptor`](/blazor-ui/api/telerik.datasource.filterdescriptor). | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * Otherwise, cast each `IFilterDescriptor` to [`CompositeFilterDescriptor`](/blazor-ui/api/Telerik.DataSource.CompositeFilterDescriptor). | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### CompositeFilterDescriptor | ||
|
|
||
| The `CompositeFilterDescriptor` exposes: | ||
NansiYancheva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * [`FilterDescriptors`](/blazor-ui/api/telerik.datasource.compositefilterdescriptor#Telerik_DataSource_CompositeFilterDescriptor_FilterDescriptors) property. This property represents another collection of `IFilterDescriptor`. To access the filtering criteria cast each `IFilterDescriptor` to a `FilterDescriptor`. | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * [`LogicalOperator`](/blazor-ui/api/telerik.datasource.compositefilterdescriptor#Telerik_DataSource_CompositeFilterDescriptor_LogicalOperator) property. This property can be either `AND` or `OR`. This property represents the logical operator applied between the instances in the `FilterDescriptors` collection. | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| When the filtering is initiated, the `CompositeFilterDescriptor` properties get different values, depending on the filter mode: | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @[template](/_contentTemplates/common/parameters-table-styles.md#table-layout) | ||
|
|
||
| | Filter Mode | FilterDescriptors Property Value | LogicalOperator Property Value | | ||
| | --- | --- | --- | | ||
| | FilterMenu | Two filter descriptor instances per each filtered field. Each filter descriptor instance gets the user input as `Value`. If there is no user input in one of the input fields in the menu then this filter descriptor instance `Value` is null. | Depending on the user choice. | | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| | FilterRow | Two filter descriptor instances per each filtered field. The second filter descriptor instance always gets null as `Value`, because there is no second input field. | AND | | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| ## Searching | ||
|
|
||
| The searching criteria are stored in an individual `IFilterDescriptor`. To access the filtering criteria, cast the `IFilterDescriptor` to `CompositeFilterDescriptor`. The `FilterDescriptors` property of the `CompositeFilterDescriptor` gets filter descriptor instances for all string fields. Each filter descriptor instance gets the user input as `Value`. The value of the `LogicalOperator` property of the `CompositeFilterDescriptor` is OR. | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| ## Sorting | ||
|
|
||
| The sorting criteria are stored in a collection of [`SortDescriptor`](/blazor-ui/api/telerik.datasource.sortdescriptor). Each `SortDescriptor` instance gives access to: | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * The `Member`—The field where the user sorts. | ||
| * The `SortDirection`—The sort direction for this sort descriptor. | ||
|
|
||
NansiYancheva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Grouping | ||
|
|
||
| Тhe grouping criteria for each group is stored in an individual collection of [`GroupDescriptor`](/blazor-ui/api/telerik.datasource.groupdescriptor). The `GroupDescriptor` class inherits the `SortDescriptor` class and gives access to the same properties as the `SortDescriptor` class. | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
NansiYancheva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Examples | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #### Obtain the FilterDescriptor, SearchFilter, SortDescriptor, GroupDescriptor in the OnRead Event Handler | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ````CSHTML | ||
| @using Telerik.DataSource | ||
| @using Telerik.DataSource.Extensions | ||
| <p>@ConsoleSim</p> | ||
| <TelerikGrid TItem="@SampleData" | ||
| OnRead="@OnReadHandler" | ||
| Sortable="true" | ||
| Groupable="true" | ||
| FilterMode="@GridFilterMode.FilterMenu" | ||
| Pageable="true" PageSize="15" | ||
| Height="400px"> | ||
| <GridToolBarTemplate> | ||
| <GridSearchBox /> | ||
| </GridToolBarTemplate> | ||
| <GridColumns> | ||
| <GridColumn Field="@nameof(SampleData.Id)" /> | ||
| <GridColumn Field="@nameof(SampleData.Name)" /> | ||
| <GridColumn Field="@nameof(SampleData.Team)" /> | ||
| <GridColumn Field="@nameof(SampleData.HireDate)" /> | ||
| </GridColumns> | ||
| </TelerikGrid> | ||
| @code { | ||
| private MarkupString ConsoleSim { get; set; } // to showcase what you get | ||
| private async Task OnReadHandler(GridReadEventArgs args) | ||
| { | ||
| string output = string.Empty; | ||
| //get the filtering and searching criteria | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| output += "<span><strong>FILTERS:</strong><span></br>"; | ||
| foreach (var item in args.Request.Filters) | ||
| { | ||
| if (item is CompositeFilterDescriptor) | ||
| { | ||
| CompositeFilterDescriptor currFilter = (CompositeFilterDescriptor)item; | ||
| output += $"START nested filter: Logical operator: {currFilter.LogicalOperator}, details:<br />"; | ||
| foreach (FilterDescriptor nestedFilter in currFilter.FilterDescriptors) | ||
| { | ||
| output += $"Filtered field: {nestedFilter.Member}, Filter operator: {nestedFilter.Operator}, Filter value: {nestedFilter.Value}<br />"; | ||
| } | ||
| output += "END nested filter<br />"; | ||
| } | ||
| } | ||
| //get the sorting criteria | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| output += "<span><strong>SORTS:</strong><span></br>"; | ||
| foreach (SortDescriptor item in args.Request.Sorts) | ||
| { | ||
| output += $"Sorted field: {item.Member}, Sort direction: {item.SortDirection} <br />"; | ||
| } | ||
| //get the grouping criteria | ||
NansiYancheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| output += "<span><strong>GROUPS:</strong><span></br>"; | ||
| foreach (GroupDescriptor item in args.Request.Groups) | ||
| { | ||
| output += $"Grouped field: {item.Member}, Group sort direction: {item.SortDirection} <br />"; | ||
| } | ||
| ConsoleSim = new MarkupString(output); | ||
| var result = PristineData.ToDataSourceResult(args.Request); | ||
| args.Data = result.Data; | ||
| args.Total = result.Total; | ||
| } | ||
| private IEnumerable<SampleData> PristineData = Enumerable.Range(1, 300).Select(x => new SampleData | ||
| { | ||
| Id = x, | ||
| Name = "name " + x, | ||
| Team = "team " + x % 5, | ||
| HireDate = DateTime.Now.AddDays(-x).Date | ||
| }); | ||
| public class SampleData | ||
| { | ||
| public int Id { get; set; } | ||
| public string Name { get; set; } | ||
| public string Team { get; set; } | ||
| public DateTime HireDate { get; set; } | ||
| } | ||
| } | ||
| ```` | ||
|
|
||
| #### Obtain the FilterDescriptor, SearchFilter, SortDescriptor, GroupDescriptor Through the Component State | ||
|
|
||
| ````CSHTML | ||
NansiYancheva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @using System.Text.Json | ||
| @using Telerik.DataSource | ||
| <p>@ConsoleSim</p> | ||
| <TelerikGrid Data="@GridData" | ||
| Sortable="true" | ||
| Groupable="true" | ||
| FilterMode="@GridFilterMode.FilterMenu" | ||
| Pageable="true" PageSize="15" | ||
| Height="400px" | ||
| OnStateChanged="@( (GridStateEventArgs<Product> args) => OnGridStateChanged(args) )"> | ||
| <GridToolBarTemplate> | ||
| <GridSearchBox /> | ||
| </GridToolBarTemplate> | ||
| <GridColumns> | ||
| <GridColumn Field="@nameof(Product.Name)" /> | ||
| <GridColumn Field="@nameof(Product.Category)" /> | ||
| <GridColumn Field="@nameof(Product.Stock)" /> | ||
| <GridColumn Field="@nameof(Product.Discontinued)" /> | ||
| </GridColumns> | ||
| </TelerikGrid> | ||
| @code { | ||
| private MarkupString ConsoleSim { get; set; } | ||
| private List<Product> GridData { get; set; } = new List<Product>(); | ||
| private async Task OnGridStateChanged(GridStateEventArgs<Product> args) | ||
| { | ||
| string output = string.Empty; | ||
| //get the searching criteria | ||
| output += "<span><strong>SEARCHING:</strong><span></br>"; | ||
| var searching = args.GridState.SearchFilter; | ||
| if (searching is CompositeFilterDescriptor) | ||
| { | ||
| CompositeFilterDescriptor currSearch = searching as CompositeFilterDescriptor; | ||
| output += $"START nested searching: Logical operator: {currSearch.LogicalOperator}, details:<br />"; | ||
| // by design, there will actually be 2 only, this showcases the concept and the types | ||
| foreach (FilterDescriptor nestedSearch in currSearch.FilterDescriptors) | ||
| { | ||
| output += $"Search field: {nestedSearch.Member}, Search operator {nestedSearch.Operator}, Search value: {nestedSearch.Value}<br />"; | ||
| } | ||
| output += "END nested searching<br />"; | ||
| } | ||
| //get the filtering criteria | ||
| output += "<span><strong>FILTERS:</strong><span></br>"; | ||
| foreach (var item in args.GridState.FilterDescriptors) | ||
| { | ||
| if (item is CompositeFilterDescriptor) | ||
| { | ||
| CompositeFilterDescriptor currFilter = item as CompositeFilterDescriptor; | ||
| output += $"START nested filter: Logical operator: {currFilter.LogicalOperator}, details:<br />"; | ||
| foreach (FilterDescriptor nestedFilter in currFilter.FilterDescriptors) | ||
| { | ||
| output += $"Filtered field: {nestedFilter.Member}, Filter operator: {nestedFilter.Operator}, Filter value: {nestedFilter.Value}<br />"; | ||
| } | ||
| output += "END nested filter<br />"; | ||
| } | ||
| } | ||
| //get the sorting criteria | ||
| output += "<span><strong>SORTS:</strong><span></br>"; | ||
| foreach (SortDescriptor item in args.GridState.SortDescriptors) | ||
| { | ||
| output += $"Sorted field: {item.Member}, Sort direction: {item.SortDirection} <br />"; | ||
| } | ||
| //get the grouping criteria | ||
| output += "<span><strong>GROUPS:</strong><span></br>"; | ||
| foreach (SortDescriptor item in args.GridState.GroupDescriptors) | ||
| { | ||
| output += $"Grouped field: {item.Member}, Group sort direction: {item.SortDirection} <br />"; | ||
| } | ||
| ConsoleSim = new MarkupString(output); | ||
| } | ||
| protected override void OnInitialized() | ||
| { | ||
| var rnd = new Random(); | ||
| for (int i = 1; i <= 12; i++) | ||
| { | ||
| GridData.Add(new Product() | ||
| { | ||
| Id = i, | ||
| Name = $"Product {i}", | ||
| Category = $"Category {i % 4 + 1}", | ||
| Stock = rnd.Next(0, 100), | ||
| Discontinued = i % 3 == 0 | ||
| }); | ||
| } | ||
| } | ||
| public class Product | ||
| { | ||
| public int Id { get; set; } | ||
| public string Name { get; set; } = string.Empty; | ||
| public string Category { get; set; } = string.Empty; | ||
| public int Stock { get; set; } | ||
| public bool Discontinued { get; set; } | ||
| } | ||
| } | ||
| ```` | ||
NansiYancheva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
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
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
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
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
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
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
Oops, something went wrong.
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.