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

Filtering with CollectionViewSource

2 Answers 445 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Steffen
Top achievements
Rank 1
Veteran
Steffen asked on 28 Jan 2021, 03:17 PM

Hi,

I'm trying to migrate from RadScheduler to RadscheduleView and I am on version 2012.1.326.40 right now.

I had a lot of filter options for the user that I implemented by filtering a CollectionViewSource that was bound to the RadScheduler's appointments source.

This doesn't seem to have any effect to the RadScheduleView though.

Is this a bug? What would be an alternative approach?

Any help would be highly appreciated.

Best Regards
Steffen

2 Answers, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 02 Feb 2021, 01:28 PM

Hello Steffen,

You can bind the AppointmentSource of the RadScheduleView to an ICollectionView created by a CollectionViewSource and apply some filtering logic. Here is a sample setup: 

public class ViewModel
    {
        private CollectionViewSource appointments;

        public ViewModel()
        {
            Appointments.Filter += Appointments_Filter;
        }

        private void Appointments_Filter(object sender, FilterEventArgs e)
        {
            if (e.Item is Appointment app)
            {
                if (app.Subject == "Front-End Meeting")
                {
                    e.Accepted = false;
                }
            }
        }

        public CollectionViewSource Appointments
        {
            get
            {
                if (this.appointments == null)
                {
                    this.appointments = new CollectionViewSource() { Source = CreateAppointments() };
                }
                return this.appointments;
            }
        }

        private ObservableCollection<Appointment> CreateAppointments()
        {
            ObservableCollection<Appointment> apps = new ObservableCollection<Appointment>();

            var app1 = new Appointment()
            {
                Subject = "Front-End Meeting",
                Start = DateTime.Today.AddHours(9),
                End = DateTime.Today.AddHours(10)
            };
            apps.Add(app1);

            var app2 = new Appointment()
            {
                Subject = "Planning Meeting",
                Start = DateTime.Today.AddHours(11),
                End = DateTime.Today.AddHours(12)
            };
            apps.Add(app2);

            return apps;
        }
    }
<telerik:RadScheduleView x:Name="ScheduleView"
                                 AppointmentsSource="{Binding Appointments.View}"  >
           
            <telerik:RadScheduleView.ViewDefinitions>
                <telerik:DayViewDefinition />
                <telerik:WeekViewDefinition />
                <telerik:MonthViewDefinition/>
                <telerik:TimelineViewDefinition/>
            </telerik:RadScheduleView.ViewDefinitions>
        </telerik:RadScheduleView>

Do give this a try and let me know, if it helps.

Regards,
Vladimir Stoyanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Steffen
Top achievements
Rank 1
Veteran
answered on 02 Feb 2021, 01:51 PM

Hello Vladimir,

it still works as expected - I made an unrelated mistake while migrating that broke the filtering.

 

Thank you!

Tags
ScheduleView
Asked by
Steffen
Top achievements
Rank 1
Veteran
Answers by
Vladimir Stoyanov
Telerik team
Steffen
Top achievements
Rank 1
Veteran
Share this question
or