Skip to content

Commit b3d2516

Browse files
Dimo DimovDimo Dimov
authored andcommitted
docs(grid): Use search descriptor in KB
1 parent 80fb29c commit b3d2516

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

knowledge-base/grid-search-numeric-fields.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,22 @@ The following sections discuss how to implement the desired behavior, what are t
4747

4848
The solution below requires familiarity with:
4949

50-
* [How to use Grid filter descriptors]({%slug components/grid/filtering%}#filter-descriptors).
51-
* [How to change the Grid state]({%slug grid-state%}).
50+
* [How to use Grid filter descriptors]({%slug components/grid/filtering%}#filter-descriptors)
51+
* [How to change the Grid state]({%slug grid-state%})
5252
* [How to invoke Razor component events from a child component](https://docs.microsoft.com/en-us/aspnet/core/blazor/components/event-handling?view=aspnetcore-6.0#eventcallback).
5353

5454

5555
## Steps
5656

5757
Here is an overview of the major steps in the example:
5858

59-
1. Add a search textbox to the [Grid toolbar]({%slug components/grid/features/toolbar%}) or outside the Grid. Do not use the default [`GridSearchBox` component]({%slug grid-searchbox%}), as it searches inside string only.
59+
1. Add a search textbox to the [Grid toolbar]({%slug components/grid/features/toolbar%}) or outside the Grid. Do not use the default [`GridSearchBox` component]({%slug grid-searchbox%}), as it searches inside string fields only.
6060
1. Handle the `oninput` event of the search textbox. Alternatively, use a search button with an `onclick` handler.
6161
1. Use the event handler to:
6262
* Create a new `CompositeFilterDescriptor`.
6363
* Iterate all searchable fields of the Grid.
6464
* For each searchable field, parse the search string and convert it the field's data type. Create a child `FilterDescriptor` object, depending on the data field type and the parsed search value.
65-
1. Apply the filter descriptors via the Grid state.
65+
1. Apply the filter descriptors to the `SearchFilter` property of the Grid state.
6666

6767

6868
## How it works
@@ -72,12 +72,10 @@ Here is an overview of the major steps in the example:
7272
* *numeric* results that are *equal to* 8
7373
* *enums* results that are *equal to* `int` 8
7474
* Date search values *must fully match* date values in the Grid to return results. The example also shows how to search by year only.
75-
* If the search value cannot be parsed to a certain type, it won't add filters for columns of this type. For example, a search value of `"8 asd"` won't return any numeric, date and boolean results
75+
* If the search value cannot be parsed to a specific data type (such as `"123 abc"`), then the code will not create additional non-string filters. This search value will not return any numeric, date and boolean results.
7676

7777
>tip It is possible to achieve different behavior, or to work around the above limitations, by using different business logic in the filter descriptor creation.
7878
79-
> The example is incompatible with [regular Grid filtering]({%slug components/grid/filtering%}). The `SetGridSearchBoxFilters` method always removes all existing filter descriptors, because the Grid and its API does not distinguish programmatic filters and filters set by the user. In addition, the total number of programmatic and user filters will exceed the abilities of the Grid filtering UI.
80-
8179

8280
## Example
8381

@@ -118,8 +116,7 @@ Here is an overview of the major steps in the example:
118116
{
119117
var state = Grid.GetState();
120118
121-
state.FilterDescriptors.Clear();
122-
state.FilterDescriptors.Add(searchDescriptors);
119+
state.SearchFilter = searchDescriptors;
123120
124121
await Grid.SetState(state);
125122
}

0 commit comments

Comments
 (0)