diff --git a/GridBlazor/CGrid.cs b/GridBlazor/CGrid.cs index 8aab781e..5949dcf9 100644 --- a/GridBlazor/CGrid.cs +++ b/GridBlazor/CGrid.cs @@ -202,6 +202,8 @@ private CGrid(HttpClient httpClient, string url, public bool SearchingHiddenColumns { get; set; } + public bool SearchingSplittedWords { get; set; } + public bool ExtSortingEnabled { get; set; } public bool HiddenExtSortingHeader { get; set; } = false; diff --git a/GridBlazor/Client/GridClient.cs b/GridBlazor/Client/GridClient.cs index dee6e11f..cf438909 100644 --- a/GridBlazor/Client/GridClient.cs +++ b/GridBlazor/Client/GridClient.cs @@ -187,10 +187,16 @@ public IGridClient Searchable(bool enable, bool onlyTextColumns) } public IGridClient Searchable(bool enable, bool onlyTextColumns, bool hiddenColumns) + { + return Searchable(enable, onlyTextColumns, false, false); + } + + public IGridClient Searchable(bool enable, bool onlyTextColumns, bool hiddenColumns, bool splittedWords) { _source.SearchingEnabled = enable; _source.SearchingOnlyTextColumns = onlyTextColumns; _source.SearchingHiddenColumns = hiddenColumns; + _source.SearchingSplittedWords = splittedWords; return this; } diff --git a/GridBlazor/Client/IGridClient.cs b/GridBlazor/Client/IGridClient.cs index 2efd3828..8d3a0872 100644 --- a/GridBlazor/Client/IGridClient.cs +++ b/GridBlazor/Client/IGridClient.cs @@ -81,6 +81,11 @@ public interface IGridClient /// IGridClient Searchable(bool enable, bool onlyTextColumns, bool hiddenColumns); + /// + /// Enable or disable searching for all columns + /// + IGridClient Searchable(bool enable, bool onlyTextColumns, bool hiddenColumns, bool splittedWords); + /// /// Enable extended sorting /// diff --git a/GridBlazor/Filtering/FilterGridODataProcessor.cs b/GridBlazor/Filtering/FilterGridODataProcessor.cs index 70f07536..ef29783f 100644 --- a/GridBlazor/Filtering/FilterGridODataProcessor.cs +++ b/GridBlazor/Filtering/FilterGridODataProcessor.cs @@ -69,8 +69,25 @@ public string Process() if (!gridColumn.Filter.IsTextColumn()) continue; List options = new List(); - var columnFilterValue = new ColumnFilterValue(column.Name, GridFilterType.Contains, _searchSettings.SearchValue); - options.Add(columnFilterValue); + if (_grid.SearchingSplittedWords) + { + var searchWords = _searchSettings.SearchValue.Split(' '); + foreach (var searchWord in searchWords) + { + var columnFilterValue = new ColumnFilterValue(column.Name, GridFilterType.Contains, searchWord); + options.Add(columnFilterValue); + } + if (searchWords.Length > 1) + { + var columnFilterCondition = new ColumnFilterValue(column.Name, GridFilterType.Condition, GridFilterCondition.Or.ToString()); + options.Add(columnFilterCondition); + } + } + else + { + var columnFilterValue = new ColumnFilterValue(column.Name, GridFilterType.Contains, _searchSettings.SearchValue); + options.Add(columnFilterValue); + } var filter = gridColumn.Filter.GetFilter(options); if (!string.IsNullOrWhiteSpace(filter)) diff --git a/GridCore/SGridCore.cs b/GridCore/SGridCore.cs index 04f20c83..085dfb5f 100644 --- a/GridCore/SGridCore.cs +++ b/GridCore/SGridCore.cs @@ -124,6 +124,8 @@ public IGridColumnCollection Columns public bool SearchingHiddenColumns { get; set; } + public bool SearchingSplittedWords { get; set; } + public bool ExtSortingEnabled { get; set; } public bool HiddenExtSortingHeader { get; set; } = false; diff --git a/GridCore/Searching/SearchGridItemsProcessor.cs b/GridCore/Searching/SearchGridItemsProcessor.cs index 958f5a36..aa5e7aa4 100644 --- a/GridCore/Searching/SearchGridItemsProcessor.cs +++ b/GridCore/Searching/SearchGridItemsProcessor.cs @@ -39,28 +39,16 @@ public IQueryable Process(IQueryable items) ParameterExpression parameter = Expression.Parameter(typeof(T), "x"); Expression binaryExpression = null; - foreach (IGridColumn column in _grid.Columns) + if (_grid.SearchingSplittedWords) { - IGridColumn gridColumn = column as IGridColumn; - if (gridColumn == null) continue; - if (gridColumn.Search == null) continue; - if (!_grid.SearchingHiddenColumns && gridColumn.Hidden) continue; - - if (binaryExpression == null) - { - binaryExpression = gridColumn.Search.GetExpression(_settings.SearchValue, - _grid.SearchingOnlyTextColumns, parameter, _grid.RemoveDiacritics); - } - else + var searchWords = _settings.SearchValue.Split(' '); + foreach (var searchWord in searchWords) { - Expression expression = gridColumn.Search.GetExpression(_settings.SearchValue, - _grid.SearchingOnlyTextColumns, parameter, _grid.RemoveDiacritics); - if (expression != null) - { - binaryExpression = Expression.OrElse(binaryExpression, expression); - } + binaryExpression = GetExpression(_grid, binaryExpression, parameter, searchWord); } } + else + binaryExpression = GetExpression(_grid, binaryExpression, parameter, _settings.SearchValue); // apply extension to items if (binaryExpression != null) @@ -71,6 +59,33 @@ public IQueryable Process(IQueryable items) return items; } + private Expression GetExpression(ISGrid grid, Expression binaryExpression, ParameterExpression parameter, string searchValue) + { + foreach (IGridColumn column in grid.Columns) + { + IGridColumn gridColumn = column as IGridColumn; + if (gridColumn == null) continue; + if (gridColumn.Search == null) continue; + if (!grid.SearchingHiddenColumns && gridColumn.Hidden) continue; + + if (binaryExpression == null) + { + binaryExpression = gridColumn.Search.GetExpression(searchValue, + grid.SearchingOnlyTextColumns, parameter, grid.RemoveDiacritics); + } + else + { + Expression expression = gridColumn.Search.GetExpression(searchValue, + grid.SearchingOnlyTextColumns, parameter, grid.RemoveDiacritics); + if (expression != null) + { + binaryExpression = Expression.OrElse(binaryExpression, expression); + } + } + } + return binaryExpression; + } + #endregion } } diff --git a/GridCore/Server/GridCoreServer.cs b/GridCore/Server/GridCoreServer.cs index af80ca50..5bbd6bc3 100644 --- a/GridCore/Server/GridCoreServer.cs +++ b/GridCore/Server/GridCoreServer.cs @@ -146,10 +146,16 @@ public IGridServer Searchable(bool enable, bool onlyTextColumns) } public IGridServer Searchable(bool enable, bool onlyTextColumns, bool hiddenColumns) + { + return Searchable(enable, onlyTextColumns, false, false); + } + + public IGridServer Searchable(bool enable, bool onlyTextColumns, bool hiddenColumns, bool splittedWords) { _source.SearchingEnabled = enable; _source.SearchingOnlyTextColumns = onlyTextColumns; _source.SearchingHiddenColumns = hiddenColumns; + _source.SearchingSplittedWords = splittedWords; return this; } diff --git a/GridCore/Server/IGridServer.cs b/GridCore/Server/IGridServer.cs index 07e685cc..8578dd37 100644 --- a/GridCore/Server/IGridServer.cs +++ b/GridCore/Server/IGridServer.cs @@ -79,6 +79,11 @@ public interface IGridServer /// IGridServer Searchable(bool enable, bool onlyTextColumns, bool hiddenColumns); + /// + /// Enable or disable searching for all columns + /// + IGridServer Searchable(bool enable, bool onlyTextColumns, bool hiddenColumns, bool splittedWords); + /// /// Enable extended sorting /// diff --git a/GridMvc/Html/HtmlGrid.cs b/GridMvc/Html/HtmlGrid.cs index e378493f..43268aaf 100644 --- a/GridMvc/Html/HtmlGrid.cs +++ b/GridMvc/Html/HtmlGrid.cs @@ -60,6 +60,12 @@ public bool SearchingHiddenColumns set { _source.SearchingHiddenColumns = value; } } + public bool SearchingSplittedWords + { + get { return _source.SearchingSplittedWords; } + set { _source.SearchingSplittedWords = value; } + } + public bool ExtSortingEnabled { get { return _source.ExtSortingEnabled; } diff --git a/GridShared/IGrid.cs b/GridShared/IGrid.cs index ad7b7729..453f7bf4 100644 --- a/GridShared/IGrid.cs +++ b/GridShared/IGrid.cs @@ -63,15 +63,21 @@ public interface IGrid bool ClearFiltersButtonEnabled { get; set; } /// - /// Set or get value of searching for all columns or only text ones + /// Set or get value of searching all columns or only text ones /// bool SearchingOnlyTextColumns { get; set; } /// - /// Set or get value of searching for all columns including hidden ones + /// Set or get value of searching all columns including hidden ones /// bool SearchingHiddenColumns { get; set; } + /// + /// Set or get value of searching all columns for splitted words + /// + bool SearchingSplittedWords { get; set; } + + /// /// Text in empty grid (no items for display) ///