How to select the same number of timeslots as the property NumberOfHoveredRows

4 posts, 0 answers
  1. Kristian
    Kristian avatar
    2 posts
    Member since:
    Nov 2012

    Posted 09 Feb 2013 Link to this post

    Hi,
    I'm new on this forum and have just bought the Telerik ASP Ajax controls.
    I have started using the Scheduler and have a problem.

    I want the scheduler to selected the same rows that are hovered (using the property NumberOfHoveredRows).
    So when the user clicks in the scheduler the rows are selected by automatic. As it is now only one row is selected.

    Is this possible to do by javascript somehow?

    I can only find the function get_selectedSlots() not set_selectedSlots().

    Please help me as I need to have this to work!

    Regards Kristian
  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2062 posts

    Posted 13 Feb 2013 Link to this post

    Hello,

    An easy and convenient way of achieving such functionality would be to use the RadScheduler OnClientTimeSlotClick client-side event handler:
    //markup code
    <telerik:RadScheduler ID="RadScheduler1" runat="server" NumberOfHoveredRows="5" OnClientTimeSlotClick="ClientTimeSlotClick" SelectedView="Dayview"></telerik:RadScheduler>
    //JavaScript
    function ClientTimeSlotClick(sender, args) {
        var timeSlotRowIndex = args.get_targetSlot().get_rawIndex().rowIndex;
        var timeSlotCellIndex = args.get_targetSlot().get_rawIndex().cellIndex;
        var numberOfHoveredRows = sender.get_numberOfHoveredRows();
        for (var i = 1; i < numberOfHoveredRows; i++) {
            var currentSlotDom = $telerik.$(".rsContentTable").children().children()[timeSlotRowIndex + i].children[timeSlotCellIndex];
            var timeSlot = sender.get_activeModel().getTimeSlotFromDomElement(currentSlotDom);               
            timeSlot.set_selected(true);
        }
     
    }

    Please find more information about RadScheduler client-side programming here.

    Kind regards,
    Boyan Dimitrov
    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.
  3. Kristian
    Kristian avatar
    2 posts
    Member since:
    Nov 2012

    Posted 13 Feb 2013 Link to this post

    Thansk!! 
    That worked perfect!

    But, i have another problem. When I do this, the timeslots are selected, but the old one is still there when i click another timeslot.
    I wan't the old ones selected to be cleared out as I click another timeslot.

    Thanks!

    Regards Kristian
  4. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2062 posts

    Posted 18 Feb 2013 Link to this post

    Hello,

    An easy and convenient way of achieving that functionality would be to modify your ClientTimeSlotClick client-side function as shown in the code snippet below:
    //JavaScript
    function ClientTimeSlotClick(sender, args) {
        $telerik.$(".rsContentTable td.rsSelectedSlot").removeClass('rsSelectedSlot');
        var timeSlotRowIndex = args.get_targetSlot().get_rawIndex().rowIndex;
        var timeSlotCellIndex = args.get_targetSlot().get_rawIndex().cellIndex;
        var numberOfHoveredRows = sender.get_numberOfHoveredRows();
        for (var i = 0; i < numberOfHoveredRows; i++) {
            var currentSlotDom = $telerik.$(".rsContentTable").children().children()[timeSlotRowIndex + i].children[timeSlotCellIndex];
            var timeSlot = sender.get_activeModel().getTimeSlotFromDomElement(currentSlotDom);
            timeSlot.set_selected(true);
        }
     
    }

    This will unselect all already selected time slots before you executing your custom code in your event handler.
    Please keep in mind that in this case your iterate counter should start from "0" instead of "1" as shown in the second highlighted area.

    Kind regards,
    Boyan Dimitrov
    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