This is a migrated thread and some comments may be shown as answers.

Filters in a RadGridView get cleared at some point automatically?

2 Answers 74 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vladimir
Top achievements
Rank 1
Veteran
Vladimir asked on 03 Sep 2020, 04:44 PM

We have this sort of filter

        private CompositeFilterDescriptor _deletedNewFilterDescriptor = new CompositeFilterDescriptor()
        {
            LogicalOperator = FilterCompositionLogicalOperator.Or,
            FilterDescriptors =
                    {
                        new FilterDescriptor("Column1", FilterOperator.IsNotEqualTo, "MyState"),
                        new FilterDescriptor("Column2", FilterOperator.IsNotEqualTo, "YourState")
                    }
        };

and at some point when we refresh the grid, the rows that should be filtered get displayed. So we have to do something like this which also fails on occasions

 

        void grd_loaded(object sender, RoutedEventArgs e)
        {
            // For some reason, adding filters in constructors gets cleared somewhere, so add in Loaded methods.
            if (!grd.FilterDescriptors.Contains(_deletedNewFilterDescriptor))
                grd.FilterDescriptors.Add(_deletedNewFilterDescriptor);
        }

 

Any help would be appreciated. Because we will have to filter those rows at the SQL fetching time and not afterwards. This means changing the existing code.

2 Answers, 1 is accepted

Sort by
0
Vladimir
Top achievements
Rank 1
Veteran
answered on 03 Sep 2020, 05:43 PM

I forgot to add this as well

        private void Grd_OnDataLoaded(object sender, EventArgs e)
        {
            // For some reason, adding filters in constructors gets cleared somewhere, so add in Loaded methods.
            Dispatcher.InvokeDelayedAction(DispatcherPriority.Background,
                () => {
                    try
                    {
                        if (!grd.FilterDescriptors.Contains(_deletedNewFilterDescriptor))
                            grd.FilterDescriptors.Add(_deletedNewFilterDescriptor);
                    }
                    catch { } // Background thread; can't really do much if there's an error.
                });
        }

0
Dilyan Traykov
Telerik team
answered on 08 Sep 2020, 06:42 AM

Hello Vladimir,

Thank you for the provided code snippets.

From your second reply, I see that you may be handling the DataLoaded event instead of the Loaded event of the control. Can you please specify whether this is intentional as the DataLoaded event will be fired on each data operation such as filtering, grouping, and sorting and I do not believe that adding the filter descriptor on each data operation would be desired.

Can you please also clarify what you mean by "fails on occasions" - is an exception or error observed or is it simply that the filters get cleared? Please also specify the occasions on which this happens.

If possible, it would be most helpful if you could isolate this undesired behavior in a small sample project so that I can investigate further and try to suggest a possible solution. Please let me know whether you would find this possible.

Regards,
Dilyan Traykov
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

Tags
GridView
Asked by
Vladimir
Top achievements
Rank 1
Veteran
Answers by
Vladimir
Top achievements
Rank 1
Veteran
Dilyan Traykov
Telerik team
Share this question
or