Combining search with additional programmatic filters
Hi,
I currently have a datagrid with the built-in text search function which filters out visible rows according to the search text (no highlighting).
I have created additional textboxes to filter on other properties for each row. I want to be able to use the text search function together with programmatic filters on other properties. For example, search for text "apple" and also only show rows where MyRowProperty > 5.
I have learnt that I cannot use the search function together with column filters. I was thinking of maybe filtering the data myself before SfDataGrid handles the data by wrapping the items source in some kind of filterable view, but I'm not sure if this would work.
Please advise me on how I could achieve this?
Kind regards,
Zia
When "ANATR" is entered in the textbox and the button is clicked, the filter predicates for the UnitPrice column are applied, and the search method is invoked for the SfDataGrid. Additionally, filtering is enabled for the SearchHelper within the button click event. As a result, the row containing "ANATR" will be displayed only if its UnitPrice is greater than 200. This functionality is working fine as expected.
private void search_Click(object sender, RoutedEventArgs e) { datagrid.Columns["UnitPrice"].FilterPredicates.Add(new FilterPredicate() { FilterType = FilterType.GreaterThan, FilterValue = 200 }); datagrid.SearchHelper.AllowFiltering = true; datagrid.SearchHelper.Search(textBox.Text); } |
UG Link: Search
Attachment: sample_45cb3633.zip
Hi,
Thanks for your help. I combined the column filters and search filter and got it working.
After further investigation, it turned out that an optimisation I had made was interfering with the expected filter result:
- My optimisation was to disable computation of the values for rows that were not visible on the screen.
- Therefore as I was filtering using the column filter, I was not seeing the expected results because rows were going out of view and their values were being removed.
Hi Zia,
We have investigated the reported scenario and understand that the unexpected results are occurring due to the optimization you implemented. However, we are a slightly unclear about the exact details of your scenario.
To assist you further, please provide the following information:
- A detailed explanation of how you are disabling the calculation for rows that are not visible.
- The code snippet related to this optimization.
- Kindly replicate the scenario in the previously shared sample so we can analyze it in context.
This information will help us investigate further and provide you an accurate solution.
Regards,
Rabina M