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

Detect when filtering is complete

5 Answers 53 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Håkan
Top achievements
Rank 1
Håkan asked on 24 Nov 2011, 09:50 AM
Hi,

I have some custom filtering of the appoinments created as in your demos.
With this kind of code (some parts left out):
public void ApplyFilter()
       {
           this.OnPropertyChanged("AppointmentsFilter");
       }
 
       public Predicate<IAppointment> AppointmentsFilter
       {
           get
           {
               return this.Filter;
           }
       }
 
       private bool Filter(IAppointment appointment)
       {
           TimeScheduleShift shift = appointment as TimeScheduleShift;
           bool match = shift != null && this.FilterByShiftType(shift);
           return match;
       }
 
 private bool FilterByShiftType(TimeScheduleShift shift)
       {
           return this.SelectedShiftTypes.Count == 0 || this.SelectedShiftTypes.Contains(shift.ShiftTypeId);
       }

I want to know when the filtering is complete, because then I need to do some calculations on the visible appointments.
I can't add an event to the Filter method, because it will be called for every appointment.
And I can't just do the calculation after I have called ApplyFilter, because the filtering is async and not ready then.

Is there another way of knowing when the filtering is complete?

Regards,
Håkan


5 Answers, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 25 Nov 2011, 12:22 PM
Hello Håkan,

I am not aware of a way to determine when the filtering has finished. We are using a CollectionView internally in RadScheduleView, which is used for grouping and filtering and it does not provide notifications when certain task is finished.

Greetings,
Valeri Hristov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Håkan
Top achievements
Rank 1
answered on 28 Nov 2011, 03:06 PM
Hi Valerie.

I solved this by setting a counter to number of appointments in the Filter method.
And for each appoinment beeing filtered I subtract the counter.
And when counter is reaching 0, I raise an event.
Do you see any potentional problems with this?
public void ApplyFilter()
       {
           filterCounter = Appointments.Count;
 
           this.OnPropertyChanged("AppointmentsFilter");
       }
 
       public Predicate<IAppointment> AppointmentsFilter
       {
           get
           {
               return this.Filter;
           }
       }
 
       private bool Filter(IAppointment appointment)
       {
           TimeScheduleShift shift = appointment as TimeScheduleShift;
           bool match = shift != null && this.FilterByShiftType(shift) && this.FilterByEmployee(shift) && this.FilterByPreliminary(shift) &&
               this.FilterByStatusOpen(shift) && this.FilterByStatusAssigned(shift) &&
               this.FilterByUserStatusAccepted(shift) && this.FilterByUserStatusWanted(shift) && this.FilterByUserStatusUnwanted(shift) && this.FilterByUserStatusAbsence(shift);
 
           shift.IsVisible = match;
 
           filterCounter--;
           if (filterCounter == 0 && Filtered != null)
               Filtered(this, EventArgs.Empty);
 
           return match;
       }

Regards,
Håkan


0
Rosi
Telerik team
answered on 01 Dec 2011, 04:02 PM
Hi Håkan,

i suggest you give it a try. If every appointment from Appointments collection goes through the Filter method everything should works as expected.

Kind regards,
Rosi
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Håkan
Top achievements
Rank 1
answered on 17 Feb 2012, 03:06 PM
Hi.

Unfortunately this didn't always work.
In some cases all appointments are not passed through the Filter method, and then my event will never be raised.

I have solved it by a timer now.
The timer starts when the filter is initialized and for each time an appointment is passed through the Filter method, I restart the timer.
So the timer will be triggered for example 500 milliseconds after the last appoinment is filtered.
I will try with lower intervall to get it as responsive as possible...

But if you know of a better solution I would appreciate it.

Regards,
Håkan
0
Yana
Telerik team
answered on 22 Feb 2012, 10:40 AM
Hi Håkan,

At the moment  we are not aware of a better solution.

Kind regards,
Yana
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
ScheduleView
Asked by
Håkan
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Håkan
Top achievements
Rank 1
Rosi
Telerik team
Yana
Telerik team
Share this question
or