We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Sf Data Grid Excel Like Filtering FilterPredicates Using Not Equals

Hi,

I found that when i uncheck one or only few items in the long list of excel like filtering, the type of FilterPredicates is using NOT EQUALS on the uncheck items instead of using EQUALS on all the checked items, it would be correct if the use case is filtering the same datatable with exactly the same data.

But in our situation, we are having dynamic datatable and we wish to store the filtering condition and reuse it on any datatable. If the NOT EQUALS filter condition is apply, it might generate a different set of result. 

So the question is, is there any way we can use the excel like filtering to achieve our use case?

Thanks and best regards,
Kevin

1 Reply

SC Saravanan C Syncfusion Team May 9, 2014 05:41 PM UTC

Hi Kevin,

 

We have analyzed your query and you can achieve your requirement to reuse same filtering condition by using FilterChanging and FilterItemsPopulated events. Please find the code snippet in below,

 

In FilterChanging event, we have created filter predicate using Equals filter type without considering checked and unchecked items. So you can reuse the filter predicate for different itemssource.

 

Code Snippet [C#]:

 

this.dataGrid.FilterChanging += dataGrid_FilterChanging;

this.dataGrid.FilterItemsPopulated += dataGrid_FilterItemsPopulated;

 

private void dataGrid_FilterChanging(object sender, Syncfusion.UI.Xaml.Grid.GridFilterEventArgs e)

{

    if (e.FilterPredicates == null || filterItems == null || !e.FilterPredicates.Any() || !filterItems.Any())

        return;

 

    e.FilterPredicates.Clear();

    var selectedItems = filterItems.Where(x => x.IsSelected);

    int I = 0;

    foreach (var item in selectedItems)

    {

        if (I == 0)

            e.FilterPredicates.Add(new FilterPredicate()

                {

                    FilterValue = item.ActualValue,

                    FilterType = FilterType.Equals,

                    FilterBehavior = FilterBehavior.StronglyTyped,

                    IsCaseSensitive = true,

                    PredicateType = PredicateType.And

                });

        else

        {

            e.FilterPredicates.Add(new FilterPredicate()

                {

                    FilterValue = item.ActualValue,

                    FilterType = FilterType.Equals,

                    FilterBehavior = FilterBehavior.StronglyTyped,

                    IsCaseSensitive = true,

                    PredicateType = PredicateType.Or

                });

 

        }

        i++;

    }

}

 

private void dataGrid_FilterItemsPopulated(object sender,

                                            Syncfusion.UI.Xaml.Grid.GridFilterItemsPopulatedEventArgs e)

{

    filterItems = e.ItemsSource as Ienumerable<FilterElement>;

    e.FilterControl.FilterMode = FilterMode.CheckboxFilter;

}

 

 

Please let us know if  this solution helps you.

 

Regards,

Saravanan C


Attachment: ExcelLikeFiltering_7f1e244f.zip

Loader.
Live Chat Icon For mobile
Up arrow icon