Filtering
Since 0.1.0-alpha.20
The members for filtering, and the types they use. Every member of
IzzyBlazor.DataGrid<TItem> is on the DataGrid API.
Properties (9)
Searchablebool = falseA search box in the toolbar, across the text columns. The words go in the address (?search=) and reach an ItemsProvider as the request's Search. With no script they apply on Enter.
@bind-Searchstring?The words searched for. Binding it (@bind-Search) on an interactive page keeps them, with sort and page, in the component.
SearchLabelstring? = "Search"The search box's name and placeholder. Defaults to "Search".
FilterRowbool = falseAdds a row of filters under the titles: a field for each column, then its filter button, which opens the column's panel, where the operator is chosen. A list, a range or a date shows what it's set to, and opens the panel too.
FilterBuilderbool = falseAdds a Filter builder button to the toolbar, for groups of conditions no column's filter can hold. What it builds goes in the address as ?filter=, and applies along with the columns' filters.
Without JavaScript: With JavaScript off the button is hidden. A filter already in the address still applies.
@bind-FilterFilter?The filter: Filter.All of a condition per filtered column (contains for text, between for numbers, equals for dates, equals or in for choices), or null for none. Binding it (@bind-Filter) on an interactive page keeps filters, sort and page in the component instead of the URL. Set it in C#, such as Filter.Where("status", FilterOperator.Equals, "Paid"); a condition no column's panel can show still applies, and shows as a tag that removes it.
FilterCaseFilterCase = FilterCase.IgnoreCaseHow text compares in the column filters and search. Defaults to FilterCase.IgnoreCase, which lowers both sides. FilterCase.Database compares text as it is and leaves it to the database's collation, so an index can serve it. An export endpoint sets Case on its own fields, or the file and the screen can differ.
FilterPanelbool = falseA row below the rows that lists the active filters, each with a button to remove it, and Clear for all of them. It's there whether or not anything is filtered, so nothing moves.
FilterFromAddressbool = falseApplies a whole filter from the address (?filter=, with the QueryPrefix), as a FilterBuilder<T> on the page writes it, along with the columns' own. Off by default, as the page may use that name itself.
Parts (3)
Components written inside DataGrid, and the columns' members, which PropertyColumn and TemplateColumn share.
DataGridSearch
Puts a DataGrid's search box, from Searchable, among your toolbar items. It stays in the bar, as a box.
PositionToolbarPosition = ToolbarPosition.StartWhere it sits, among the items of that position in the order they're written.
DataGridFilterBuilder
Puts a DataGrid's Filter builder button, from FilterBuilder, among your toolbar items. It stays in the bar, at the start unless Position says otherwise.
PropertyColumn<TItem, TValue>
A column that shows one property of each item, formatted, and can sort by it. The title and sort key come from the property ([Display(Name)] is used when present).
Filterablebool = falseAdds a filter button to this column's header. In a Table: a text box for text (matching anywhere, ignoring case), Min and Max boxes for numbers (keeping the values between them; either may be empty), a date input for dates (matching the day), a list of checkboxes for enums and booleans. In a DataGrid, text, numbers and dates choose an operator above the value. A TemplateColumn<T> filters by its FilterBy text.
FilterOperatorsIReadOnlyList<FilterOperator>?The operators this column's filter offers, the first being the default, such as [FilterOperator.GreaterThanOrEqual, FilterOperator.Between]; a condition with any other matches nothing, whoever writes it. With more than one, a Table's column chooses in a Select as a DataGrid's does. For text, numbers and dates.
FilterFunc<FieldFilter, Expression<Func<TItem, bool>>?>?Builds this column's filter condition yourself, for a computed value or one stored differently from how it's shown. It gets the condition (operator and values parsed for the column's type) and returns the filter on the item, or null for the usual one. See Filter.
FilterValuesFilterValuesLoader?Makes this column's filter a list of checkboxes with a search, its values found here when the panel opens: a page at a time, narrowed by the other filters, and loading more on scroll. Use ToResultAsync to read them from a query. On a static page the script asks the page's own address for them, so a search renders the page again. With no script, the column shows its usual filter. Not with FilterOperators.
Without JavaScript: With JavaScript off, the column shows its usual filter in place of the list.
FilterListbool = falseAs FilterValues, reading a text column's values from the table's Items. With an ItemsProvider there's nothing to read, so use FilterValues.
Without JavaScript: With JavaScript off, the column shows its usual filter in place of the list.
FilterTemplateRenderFragment<FilterTemplateContext>?This column's own controls, in its filter panel above Clear and Apply. Spread the context's Attributes on a control and its value filters by the column's first operator, or several values by FilterOperator.In. With Filter, a value can mean anything. Works with no script. In a filter row, the cell opens the panel. Not with FilterValues or FilterList.
FilterTextFunc<IReadOnlyList<string?>, string>? (computed)What a FilterTemplate's filter says in its row and tag, given its values, for values that aren't what people read. Defaults to the values themselves.
Types (7)
FieldFilter
recordA condition on one field: total ge 100. The values are parsed for the field's type when the filter is applied (text as the person writes it in the current culture, or the invariant form); a value that doesn't parse matches nothing.
| Member | Description |
|---|---|
Field string | The field's key. |
Operator FilterOperator | How the field's value compares. |
Value object? | The value to compare with. For |
Value2 object? | The upper end for |
MatchCase bool | For text: match upper and lower case exactly, and for equality, spaces too. Text ignores case by default. |
Values IReadOnlyList<object?> | The values of an |
Filter
recordA filter on data: a condition on one field (FieldFilter), conditions joined by and or or (FilterGroup), or the opposite of one (NotFilter). Fields are named by their key (a column's SortKey, or a DataField<T>'s Key). It becomes a LINQ expression on the fields' own properties, so an EF Core query filters in the database; a value never becomes code.
| Member | Description |
|---|---|
Parse(string text) | Reads a filter written in the subset of OData's |
Find(string field) | The condition on |
FilterCase
enumHow text compares in a filter.
| Value | Description |
|---|---|
IgnoreCase | Upper and lower case are the same: both sides are lowered, which a database index can't serve. The default. |
MatchCase | Upper and lower case differ, as far as the data's own comparison goes: text is compared as it is. In memory, that's exact. A database still has its say: SQLite's |
Database | Text is compared as it is, and the database's collation decides, so an index can serve it. On a list in memory, that's the same as |
FilterOperator
enumHow a FieldFilter compares. Which ones a field takes depends on its type: text takes the text operators, equality, the lists and the empty checks; numbers and dates the comparisons, FilterOperator.Between and the lists, and dates FilterOperator.OnDay; enums, booleans and Guids equality and the lists. Types that can be null add the null checks. An operator a field doesn't take matches nothing.
| Value | Description |
|---|---|
Equals | Equal to the value (text ignores case unless |
NotEquals | Not equal to the value. |
LessThan | Less than the value. |
LessThanOrEqual | Less than or equal to the value. |
GreaterThan | Greater than the value. |
GreaterThanOrEqual | Greater than or equal to the value. |
Between | |
Contains | Text that contains the value. |
DoesNotContain | Text that doesn't contain the value (or is null). |
StartsWith | Text that starts with the value. |
EndsWith | Text that ends with the value. |
In | Any of the values in |
NotIn | None of the values in |
IsNull | No value. |
IsNotNull | Any value. |
IsEmpty | Text that is empty or null. |
IsNotEmpty | Text that has at least one character. |
OnDay | A date on the day in the value. A |
FilterTemplateContext
classWhat a column's FilterTemplate gets: the filter as it stands, and what its controls need to change it. Spread Attributes on a control and it works on every kind of page; its value still needs setting.
| Member | Description |
|---|---|
Name string | The column's key in the address, such as |
Operator FilterOperator | The operator its value applies with: the column's first in |
Values IReadOnlyList<string?> | The values it's set to, none when it isn't. More than one makes an |
Value string | The first of |
To string | The upper end, for a column whose operator is |
IsFiltered bool | Whether the column is filtered. |
Attributes IReadOnlyDictionary<string, object> | For a control that holds the one value, such as an |
ToAttributes IReadOnlyDictionary<string, object> | As |
object> CheckboxAttributes(string value) | For a native checkbox that adds this value: as |
Has(string value) | Whether this value is among |
SetAsync(string? value) | Filters by this value on an interactive page, or removes the filter with null or "". |
SetValuesAsync(IEnumerable<string?> values) | Filters by these values on an interactive page, or removes the filter with none. |
FilterValuesLoader
delegateFinds the values a column's filter can list. It must keep what's ticked listed; the library adds any it leaves out.
| Member | Description |
|---|---|
Target object? | |
Method MethodInfo | |
BeginInvoke(FilterValuesRequest request, AsyncCallback callback, object object) | |
EndInvoke(IAsyncResult result) | |
Invoke(FilterValuesRequest request) |
ToolbarPosition
enumWhere an item of a Toolbar sits.
| Value | Description |
|---|---|
Start | At the start (the left in left-to-right text), the default. |
Center | In the middle, kept centered between the start and the end. |
End | At the end, before the "…" menu. |