Skip to content

Commit 146ee62

Browse files
committed
Add filtering action with multi columns.
1 parent 1b41349 commit 146ee62

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

Client/BlazorWASAM-Multi-Column.Client.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0" />
1111
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0" PrivateAssets="all" />
1212
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0" PrivateAssets="all" />
13-
<PackageReference Include="Syncfusion.Blazor" Version="18.1.0.53" />
13+
<PackageReference Include="Syncfusion.Blazor.DropDowns" Version="20.2.0.46" />
14+
<PackageReference Include="Syncfusion.Blazor.Themes" Version="20.2.0.46" />
1415
<PackageReference Include="System.Net.Http.Json" Version="3.2.0" />
1516
</ItemGroup>
1617

Client/Pages/Index.razor

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Welcome to your new app.
1313
<div class="control-section col-lg-12">
1414
<div id="remote-data" class="col-lg-6">
1515
<div class="content">
16-
<SfComboBox TValue="string" TItem="Product" PopupWidth="700px" DataSource="@_productsList" PopupHeight="400px" CssClass="e-multi-column" Placeholder="Select a Product">
16+
<SfComboBox @ref="selectProduct" TValue="string" TItem="Product" PopupWidth="700px" DataSource="@_productsList" PopupHeight="400px" CssClass="e-multi-column" Placeholder="Select a Product" AllowFiltering="true">
1717
<ComboBoxTemplates TItem="Product">
1818
<HeaderTemplate>
1919
<table><tr><th class="e-text-center">Product ID</th><th width="240px">Product Name</th><th>Unit Price</th><th>Units In Stock</th><th>Units On Order</th></tr></table>
@@ -23,6 +23,7 @@ Welcome to your new app.
2323
</ItemTemplate>
2424
</ComboBoxTemplates>
2525
<ComboBoxFieldSettings Text="ProductName" Value="ProductID"></ComboBoxFieldSettings>
26+
<ComboBoxEvents TValue="string" TItem="Product" Filtering="OnFiltering"></ComboBoxEvents>
2627
</SfComboBox>
2728
</div>
2829
</div>
@@ -31,10 +32,30 @@ Welcome to your new app.
3132

3233
@code{
3334

35+
SfComboBox<string, Product> selectProduct;
36+
3437
private Product[] _productsList;
3538

3639
protected override async Task OnInitializedAsync()
3740
{
3841
_productsList = await Http.GetFromJsonAsync<Product[]>("Product");
3942
}
43+
// Filter event
44+
private async Task OnFiltering(FilteringEventArgs args)
45+
{
46+
//Prevent the default filtering action and make custom seacrh.
47+
args.PreventDefaultAction = true;
48+
var CustomSearch = new WhereFilter();
49+
var predicate = new List<WhereFilter>();
50+
// Add multiple predicate and make filter action in multiple columns.
51+
predicate.Add(new WhereFilter() { Condition = "or", Field = "ProductName", value = args.Text, Operator = "contains", IgnoreCase = true });
52+
predicate.Add(new WhereFilter() { Condition = "or", Field = "UnitPrice", value = args.Text, Operator = "contains", IgnoreCase = true });
53+
predicate.Add(new WhereFilter() { Condition = "or", Field = "UnitsInStock", value = args.Text, Operator = "contains", IgnoreCase = true });
54+
predicate.Add(new WhereFilter() { Condition = "or", Field = "UnitsOnOrder", value = args.Text, Operator = "contains", IgnoreCase = true });
55+
CustomSearch = WhereFilter.Or(predicate);
56+
var query = new Query().Where(CustomSearch);
57+
// call the FilterAsync public method and pass the data source and modified query.
58+
await selectProduct.FilterAsync(_productsList, query);
59+
}
60+
4061
}

Client/wwwroot/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
<base href="/" />
99
<link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
1010
<link href="css/app.css" rel="stylesheet" />
11-
<link href="_content/Syncfusion.Blazor/styles/bootstrap4.css" rel="stylesheet" />
11+
<link href="_content/Syncfusion.Blazor.Themes/bootstrap5.css" rel="stylesheet" />
12+
<script src="_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor.min.js" type="text/javascript"></script>
1213
</head>
1314

1415
<body>

0 commit comments

Comments
 (0)