- Notifications
You must be signed in to change notification settings - Fork 80
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
+417 −59
Merged
Changes from all 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,343 @@ | ||
--- | ||
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 | ||
--- | ||
| ||
| ||
## Data Operation 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: | ||
| ||
* Components that [expose an `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. | ||
* [Filter]({%slug filter-overview%}) | ||
* [Gantt]({%slug gantt-overview%}) | ||
* [TreeList]({%slug treelist-overview%}) | ||
| ||
## Get Sort, Filter, Group, and Search Descriptors | ||
| ||
You can obtain the applied filtering, searching, sorting, and grouping criteria in two ways: | ||
| ||
* [Through the OnRead Event](#through-the-onread-event) | ||
* [Through the Component's State](#through-the-component-state) | ||
| ||
### Through the OnRead Event | ||
| ||
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. | ||
// 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 | ||
} | ||
```` | ||
| ||
See the [complete example](#example-with-onread-event-handler) at the bottom of the article. | ||
| ||
### Through the Component State | ||
| ||
Use the component's state property of the `OnStateChanged` event argument. This approach applies to the Gantt, Grid, and TreeList because they expose the state feature. For example: | ||
| ||
````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 | ||
} | ||
```` | ||
| ||
See the [complete example](#example-with-component-state) at the bottom of the article. | ||
| ||
| ||
## Filtering | ||
| ||
The `args.Request.Filters` and the `args....State.FilterDescriptors` are collections of [`IFilterDescriptor`](/blazor-ui/api/Telerik.DataSource.IFilterDescriptor). To access the filtering criteria, such as the user input to filter by, cast each `IFilterDescriptor` from the respective collection: | ||
| ||
* If the component is of type input or select, such as the AutoComplete, ComboBox, DropDownList, MultiColumnComboBox, MultiSelect, cast the first `IFilterDescriptor` from the collection to [`FilterDescriptor`](/blazor-ui/api/telerik.datasource.filterdescriptor). | ||
* Otherwise, cast each `IFilterDescriptor` from the `args.Request.Filters` collection, respectively from the `args....State.FilterDescriptors` collection, to [`CompositeFilterDescriptor`](/blazor-ui/api/Telerik.DataSource.CompositeFilterDescriptor). | ||
| ||
### CompositeFilterDescriptor | ||
| ||
The `CompositeFilterDescriptor` exposes: | ||
| ||
* The [`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`. When the Filter component gets groupable filtering, cast each `IFilterDescriptor` to another `CompositeFilterDescriptor`. | ||
* The [`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. | ||
| ||
When the filtering is initiated, the `CompositeFilterDescriptor` properties get different values depending on the filter mode: | ||
| ||
@[template](/_contentTemplates/common/parameters-table-styles.md#table-layout) | ||
| ||
| Filter Mode | FilterDescriptors Property Value | LogicalOperator Property Value | | ||
| --- | --- | --- | | ||
| `FilterMenu` | Two filter descriptor instances for 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's choice. | | ||
| `FilterRow` | Two filter descriptor instances for each filtered field. The second filter descriptor instance always gets null as `Value`, because there is no second input field. | AND | | ||
| ||
| ||
## Searching | ||
| ||
The searching criteria in a Grid or TreeList are stored in an individual `IFilterDescriptor`. Cast it to [`CompositeFilterDescriptor`](#compositefilterdescriptor). The `CompositeFilterDescriptor` holds one child `FilterDescriptor` for each searchable string column. Each `FilterDescriptor` has the same `Value`, which is the user's search input. The value of the `LogicalOperator` property of the `CompositeFilterDescriptor` is `OR`. | ||
| ||
| ||
## Sorting | ||
| ||
The sorting criteria in a Grid, TreeList or Gantt are stored in a collection of [`SortDescriptor`](/blazor-ui/api/telerik.datasource.sortdescriptor) objects. Each `SortDescriptor` instance gives access to: | ||
* 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 | ||
When the [`SortMode`](/blazor-ui/api/Telerik.Blazor.SortMode) is `Multiple`, you may need to consider the order of the `SortDescriptor` instances. The first applied sorting criteria take precedence over all others. If there are equal values in the first sorted items, then those items are sorted by the following sorting criteria. | ||
| ||
| ||
## Grouping | ||
| ||
Тhe grouping criteria for each group are stored in an individual collection of [`GroupDescriptor`](/blazor-ui/api/telerik.datasource.groupdescriptor) objects. The `GroupDescriptor` class inherits the `SortDescriptor` class and gives access to the same properties as the `SortDescriptor` class. | ||
| ||
The user may group by multiple fields. The groups for subsequent fields will be nested within their parent groups. The grouping criteria from the parent group are stored in the first `GroupDescriptor` instance from the collection. | ||
| ||
NansiYancheva marked this conversation as resolved. Show resolved Hide resolved | ||
| ||
## Example with OnRead Event Handler | ||
| ||
You can obtain the FilterDescriptor, SortDescriptor, and GroupDescriptor in the `OnRead` event handler. | ||
| ||
````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. | ||
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. | ||
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. | ||
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; } | ||
} | ||
} | ||
```` | ||
| ||
## Example with Component State | ||
| ||
You can obtain the FilterDescriptor, SearchFilter, SortDescriptor, and GroupDescriptor through the component's 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 />"; | ||
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 | ||
| ||
## See Also | ||
| ||
* [AutoComplete OnRead Event]({%slug autocomplete-events%}#onread) | ||
* [ComboBox OnRead Event]({%slug components/combobox/events%}#onread) | ||
* [DropDownList OnRead Event]({%slug components/dropdownlist/events%}#onread) | ||
* [Filter Overview]({%slug filter-overview%}) | ||
* [Gantt State]({%slug gantt-state%}) | ||
* [Grid OnRead Event]({%slug components/grid/manual-operations%}) | ||
* [Grid State]({%slug grid-state%}) | ||
* [MultiColumnComboBox OnRead Event]({%slug multicolumncombobox-events%}#onread) | ||
* [MultiSelect OnRead Event]({%slug multiselect-events%}#onread) | ||
* [TreeList State]({%slug treelist-state%}) |
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.