/// <summary> /// This method applies the filter value. /// </summary> protected void OnFilterInput() { //start with a new list if (FilteredList == null) { FilteredList = new List <T>(); } else { FilteredList?.Clear(); } //used when there are more than one filter values List <T> removeList = new List <T>(); bool firstFilter = false; //for each filter input foreach (KeyValuePair <string, string> entry in FilterDictionary) { if (!string.IsNullOrWhiteSpace(entry.Value)) { if (!firstFilter) //get all the matches for the first filter value { foreach (T item in OriginalList) { string columnValue = typeof(T).GetProperty(entry.Key)?.GetValue(item).AsString().Trim(); if (columnValue.Contains(entry.Value, StringComparison.CurrentCultureIgnoreCase)) { FilteredList.Add(item); } } firstFilter = FilteredList.Count > 0; } else { foreach (T item in FilteredList) //for subsequent filter value build a list of items that do not match { string columnValue = typeof(T).GetProperty(entry.Key)?.GetValue(item).AsString().Trim(); if (!columnValue.Contains(entry.Value, StringComparison.CurrentCultureIgnoreCase)) { removeList.Add(item); } } } } } //remove the items that do not match the filters FilteredList = FilteredList.Except(removeList).ToList(); //set the FilterActive flag FilterActive = FilteredList.Count > 0; SetPageCount(FilteredList); GetPage("first"); }