Resource filter issue

8 posts, 1 answers
  1. Esben
    Esben avatar
    11 posts
    Member since:
    Dec 2012

    Posted 19 Dec 2012 Link to this post

    I have set up the resources for my scheduler like in this example: http://www.telerik.com/help/aspnet-ajax/scheduler-using-datasource-property.html. I have the scheduler to group by the Room resource.

    I have then created a custom filter where the user can select a subset of resources (rooms). When the user change the filter, I alter the Rooms property to hold the selected rooms and call RadScheduler.Rebind(). This does, however, not change anything. All resources are still displayed in the calendar. Am I using the correct approach?
  2. Esben
    Esben avatar
    11 posts
    Member since:
    Dec 2012

    Posted 20 Dec 2012 Link to this post

    Ok, I found a solution that seems to work, but I'm not sure if it's ugly or not....

    I simply clear the collection of resource types everytime the user changes the filter and applies the filter in the Rooms property. The user selects rooms in the control SelectRoom and clicks a button. The button eventhandler then calls a method that clears the Room resource type and adds it again. Is this the right way to go?

    protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    AddOrUpdateResource();
                }
            }
             
    private void AddOrUpdateResource()
            {
                RadScheduler1.ResourceTypes.Clear();
                var rt = new ResourceType("Room")
                {
                    DataSource = Rooms,
                    KeyField = "RoomNo",
                    ForeignKeyField = "RoomNo",
                    TextField = "RoomName"
                };
                RadScheduler1.ResourceTypes.Add(rt);
            }
             
    protected void FilterButton_OnClick(object sender, EventArgs e)
            {
                AddOrUpdateResource();
            }
             
    private List<Room> Rooms
            {
                get
                {
                    var sessRooms = Session[RoomKey] as List<Room>;
                    if (sessRooms == null)
                    {
                        sessRooms = _backendManager.GetRooms();
                        Session[RoomKey] = sessRooms;
                    }
     
                    var selectedRoomNumbers =
                        (from ListItem item in SelectRoom.Items where item.Selected select item.Value).ToList();
                    if (selectedRoomNumbers.Any())
                    {
                        sessRooms = sessRooms.Where(x => selectedRoomNumbers.Contains(x.RoomNo)).ToList();
                    }
     
                    return sessRooms;
                }
                set { Session[RoomKey] = value; }
            }
  3. Plamen
    Admin
    Plamen avatar
    3080 posts

    Posted 20 Dec 2012 Link to this post

    Hi Esben,

     
    The approach you are using looks correct. I am attaching one sample web page where similar behavior have been implemented  with a RadCombobox with CheckBoxes.

    Hope this will be helpful.

    Regards,
    Plamen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  4. Esben
    Esben avatar
    11 posts
    Member since:
    Dec 2012

    Posted 20 Dec 2012 Link to this post

    Hi Plamen

    Thanks for your response. So by agreeing to my approach, do you say that Rebind() does not rebind the datasource of resourcetypes? Does it only rebind the scheduler's datasource? Or neither?
  5. Answer
    Plamen
    Admin
    Plamen avatar
    3080 posts

    Posted 21 Dec 2012 Link to this post

    Hi Esben,

    After reviewing the code you provided once again I would rather recommend you to use the approach suggested in the project I sent you in my previous post.

    As for the Rebind method it is rebinding both the appointments and returning the resource types to their initial state and count.

    Hope this will be helpful.

    All the best,
    Plamen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. Esben
    Esben avatar
    11 posts
    Member since:
    Dec 2012

    Posted 03 Jan 2013 Link to this post

    I have now implemented an approach similar to the one in the example - I agree that this way of doing it seems more reasonable.

    The custom filters work fine, when I filter by a resource type which is used in the GroupBy property of the RadScheduler (in this situation the columns of the resources that are not selected in the filter are simply removed from the scheduler). But if I try to filter by a resource type which is not used in the GroupBy property, this method does not work.

    How do I filter by resource types that are not used in GroupBy?
  7. Esben
    Esben avatar
    11 posts
    Member since:
    Dec 2012

    Posted 03 Jan 2013 Link to this post

    I solved it by setting Appointment.Visible to true/false in the OnAppointmentDataBound event.

    Please let me know if that is not the most efficient way to do it.
  8. Plamen
    Admin
    Plamen avatar
    3080 posts

    Posted 07 Jan 2013 Link to this post

    Hi Esben,

     
    Yes indeed, when you are trying to filter the Appointments that are not used in the GroupBy property a nice way to achieve it is by hiding them in the AppointmentDataBound event as you did in your scenario.

    Kind regards,
    Plamen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top