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.
Unfortunately, activation email could not send to your email. Please try again.

Sf Data Grid Excel Like Filtering FilterPredicates Using Not Equals

Thread ID:

Created:

Updated:

Platform:

Replies:

116275 May 7,2014 10:50 PM May 9,2014 01:41 PM WinRT 1
loading
Tags: SfDataGrid
Kevin Kuan
Asked On May 7, 2014 10:50 PM

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

Saravanan C [Syncfusion]
Replied On May 9, 2014 01:41 PM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;