Detect when filtering is complete

6 posts, 0 answers
  1. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 24 Nov 2011 Link to this post

    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


  2. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 25 Nov 2011 Link to this post

    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 >>

  3. DevCraft banner
  4. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 28 Nov 2011 Link to this post

    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


  5. Rosi
    Admin
    Rosi avatar
    2527 posts

    Posted 01 Dec 2011 Link to this post

    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 >>

  6. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 17 Feb 2012 Link to this post

    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
  7. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 22 Feb 2012 Link to this post

    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 >>
Back to Top
DevCraft banner