Filter items by contains operator.
public const Operator ContainsHi Byron,
Greetings from Syncfusion support.
Query 1 : Is it possible to type the "contains" operator in the default/basic filter bar?We suggest you to refer to the below documentation for more details regarding changing the default operator for the FilterBar. In the below documentation we have changed the default operator for the CustomerID column.
Query 2 & 3: Is it possible to type something that means "not blank"?Is it possible to pre-filter a column for not blank?We are not clear about these query. We suspect that you would like to filter a column on initial rendering. If so, then we suggest you to refer to the below documentation for more details regarding filtering a Grid on its initial rendering.
Please refer the above suggestions, and if we have misunderstood your requirement or if you are still facing difficulties then kindly share with us the following details for better assistance.
- Share with us a video demo showing your complete requirement and the problem you are facing.
- Share with us a detailed description of your complete requirement.
The provided information will help us analyze the problem, and provide you a solution as early as possible.
Regards,Renjith R
|
<SfGrid DataSource="@Orders" AllowFiltering="true">
<GridFilterSettings>
<GridFilterColumns>
<GridFilterColumn Field="CustomerID" MatchCase=false Operator="Operator. NotEqual" Predicate="and" Value="@val"></GridFilterColumn>
</GridFilterColumns>
</GridFilterSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" FilterSettings="@(new FilterSettings{ Operator = Operator.Contains })" Width="150"></GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>you
</SfGrid> |
|
<SfGrid DataSource="@Orders" AllowFiltering="true">
<GridFilterSettings>
<GridFilterColumns>
<GridFilterColumn Field="CustomerID" MatchCase=false Operator="Operator. NotEqual" Predicate="and" Value="@val"></GridFilterColumn>
</GridFilterColumns>
</GridFilterSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" FilterSettings="@(new FilterSettings{ Operator = Operator.Contains })" Width="150"></GridColumn>
. . .
</SfGrid>
@code{
public List<Order> Orders { get; set; }
public string val = null;
. ..
} |
Hi Byron,
Query: Is it possible to type the "contains" operator in the default/basic filter bar? -- I can type TRUD and get back all the Trudeau's. But I'd like to be able to type "Contains 'J', and get back Jane, Joe and Justin. (That's what "contains" means to me.)
We have validated your query and you want to perform filtering operation for a column that contains the particular entered value.
By default, the filter operator for column is Startswith. You can change the filter. You can change the default filter operator by extending FilterSettings property in the column. After typing value(J) in filterbar, it will filters the values which contains the given value(J) in the column values.
<SfGrid DataSource="@Orders" AllowFiltering="true"><GridFilterSettings><GridFilterColumns><GridFilterColumn Field="CustomerID" MatchCase=false Operator="Operator. NotEqual" Predicate="and" Value="@val"></GridFilterColumn></GridFilterColumns></GridFilterSettings><GridColumns><GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn><GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" FilterSettings="@(new FilterSettings{ Operator = Operator.Contains })" Width="150"></GridColumn><GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn><GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn></GridColumns>you</SfGrid>
Query: Is it possible to type something that means "not blank"? Is it possible to pre-filter a column for not blank?
We have validated the query and we might suspect that you want to perform filtering operation for particular column which does not contains null value at initially. You can achieve your requirement by using below way.
<SfGrid DataSource="@Orders" AllowFiltering="true"><GridFilterSettings><GridFilterColumns><GridFilterColumn Field="CustomerID" MatchCase=false Operator="Operator. NotEqual" Predicate="and" Value="@val"></GridFilterColumn></GridFilterColumns></GridFilterSettings><GridColumns><GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn><GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" FilterSettings="@(new FilterSettings{ Operator = Operator.Contains })" Width="150"></GridColumn>. . .</SfGrid>@code{public List<Order> Orders { get; set; }public string val = null;. ..}
So it will filter the CustomerID column and shows the values which does not contains null values.
If you want to perform filtering operation for null values, then you can type null in filterbar and press enter. It will show all the rows which contains null value for particular column.
Please let us know if you have any concerns.
Regards,Rahul
If you look at this SyncFusion page https://blazor.syncfusion.com/documentation/datagrid/filtering/ , under the sub-head "Fiter bar", the documentation status that "you can enter the following filter expressions (operators) manually in the filter bar". This doesn't just _imply_ it directly states that you can override the "default" action.
However.... (a) "Contains" is not listed in this table, and (b) = and * are BOTH listed as "Startwith" (one for strings and one for dates). Was it deliberate to not let a user type an operator for "contains"? I appreciate that you have told me twice that I can change the default, but that is NOT what I asked. I asked "Is it possible to type the "contains" operator in the default/basic filter bar?" I gather that your answer is "no, you cannot type it but you can change the default." Is this correct?
For Query 2:
Filtering the initial display was, I guess, a "Query 3". Query two is "Is it possible to TYPE [in the filter bar], something that means "not blank?"
Use case:
The user is looking at a grid.
The grid has 80,000 contacts.
Half of the contacts have a blank or null for "email address"
The user, at run time, all on his or her own, says to himself "I'd like to look at just the ones with email addresses".
What, if anything, can they type in the filter bar to eliminate all the blanks.?
Thank you.
|
<SfGrid @ref="Grid" DataSource="@Orders" AllowFiltering="true">
<GridEvents OnActionBegin="Begin" TValue="Order"></GridEvents>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<FilterTemplate>
<SfTextBox @ref="TextBox" Placeholder="Customer Name" ID="CustomerID" @onkeydown="@Enter" Value="@((string)(context as PredicateModel).Value)" ></SfTextBox>
</FilterTemplate>
</GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
</SfGrid>
@code{
SfTextBox TextBox;
SfGrid<Order> Grid;
public List<Order> Orders { get; set; }
public string val = null;
. . .
public async Task Enter(KeyboardEventArgs e)
{
if (e.Code == "Enter" || e.Code == "NumpadEnter")
{
//you can get the entered value in text box reference(TextBox.Value) and perform filter operation using FilterByColumn method with typed operator and value
await Grid.FilterByColumn("CustomerID", operator, value);
}
}
} |
|
<SfGrid @ref="Grid" DataSource="@Orders" AllowFiltering="true">
<GridEvents OnActionBegin="Begin" TValue="Order"></GridEvents>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<FilterTemplate>
<SfTextBox @ref="TextBox" Placeholder="Customer Name" ID="CustomerID" @onkeydown="@Enter" Value="@((string)(context as PredicateModel).Value)" ></SfTextBox>
</FilterTemplate>
</GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
</SfGrid>
@code{
SfTextBox TextBox;
SfGrid<Order> Grid;
public List<Order> Orders { get; set; }
. . .
public async Task Enter(KeyboardEventArgs e)
{
if (e.Code == "Enter" || e.Code == "NumpadEnter")
{
await Grid.FilterByColumn("CustomerID", "notequal", TextBox.Value.Replace('"', ' ').Trim());
}
}
} |