Skip to content

Commit

Permalink
improve quick search
Browse files Browse the repository at this point in the history
  • Loading branch information
pwelter34 committed Aug 27, 2024
1 parent 91bf192 commit b266724
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/LoreSoft.Blazor.Controls/Data/DataGrid.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,16 @@ protected async Task ApplyFilters()
}


public async Task QuickSearch(string searchText)
public async Task QuickSearch(string searchText, bool clearFilter = false)
{

RootQuery.Filters.Clear();
if (clearFilter)
RootQuery.Filters.Clear();
else
RootQuery.Filters.RemoveAll(f => f.Id == nameof(QuickSearch));

if (!string.IsNullOrWhiteSpace(searchText))
{
RootQuery.Logic = QueryLogic.Or;
var quickSearch = new QueryGroup { Id = nameof(QuickSearch), Logic = QueryLogic.Or };

// all filterable string columns
foreach (var column in Columns.Where(c => c.Filterable && c.Type == typeof(string)))
Expand All @@ -114,8 +116,10 @@ public async Task QuickSearch(string searchText)
Operator = QueryOperators.Contains,
Value = searchText
};
RootQuery.Filters.Add(filter);
quickSearch.Filters.Add(filter);
}

RootQuery.Filters.Add(quickSearch);
}

await RefreshAsync(true);
Expand Down
2 changes: 1 addition & 1 deletion src/LoreSoft.Blazor.Controls/Query/QueryGroup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;

namespace LoreSoft.Blazor.Controls;

Expand Down

0 comments on commit b266724

Please sign in to comment.