# Preserving the ButtonGroup View for Mobile Rendering in Scheduler

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Progress Telerik UI for ASP.NET MVC Scheduler</td>
 </tr>
 <tr>
  <td>Progress Telerik UI for ASP.NET MVC version</td>
  <td>Created with the 2023.3.1114 version</td>
 </tr>
</table>

## Description

How can I prevent the transmutation from a ButtonGroup to a DropDownList for different screen sizes when working with the Telerik UI for ASP.NET MVC Scheduler with Adaptive Rendering ?

## Solution

Follow the steps below to achieve the desired scenario:

1. Create a variable that will hold the DOM representation of the ButtonGroup. Which will contain the `day`, `month`, `agenda`, and `week`, `timeline`, and `year` buttons.
2. Subscribe to the [document.ready()](https://learn.jquery.com/using-jquery-core/document-ready/) event.
3. Within the handler, replace the transformed DropDownList element by using the [replaceWith()](https://api.jquery.com/replaceWith/) method.
4. From there, add a click handler to each of the buttons from the previously created ButtonGroup. And based on an assertion, call the client-side [view()](https://docs.telerik.com/kendo-ui/api/ui/scheduler/methods/view) method of the Scheduler with the appropriate view name.
5. To change a given button's state upon selection, add the [`k-selected`](https://docs.telerik.com/kendo-ui/styles-and-layout/components-rendering-overview#state-classes) state class.
6. Subscribe to the [window.resize](https://developer.mozilla.org/en-US/docs/Web/API/Window/resize_event) event and replace the transformed DropDownList when the view dimensions are changed.

```Razor Index.cshtml
@(Html.Kendo().Scheduler<Kendo.Mvc.Examples.Models.Scheduler.MeetingViewModel>()
    .Name("scheduler")
    .Date(new DateTime(2022, 6, 13))
    .StartTime(new DateTime(2022, 6, 13, 7, 00, 00))
    .Height(600)
    .Views(views =>
    {
        views.DayView();
        views.WeekView();
        views.MonthView(mv => mv.Selected(true));
        views.YearView();
        views.AgendaView();
        views.TimelineView();
    })
    .Mobile(MobileMode.Phone)
    .Timezone("Etc/UTC")
    .Resources(resource =>
    {
        resource.Add(m => m.RoomID)
            .Title("Room")
            .DataTextField("Text")
            .DataValueField("Value")
            .DataColorField("Color")
            .BindTo(new[] {
                    new { Text = "Meeting Room 101", Value = 1, Color = "#6eb3fa" },
                    new { Text = "Meeting Room 201", Value = 2, Color = "#f58a8a" }
            });
        resource.Add(m => m.Attendees)
            .Title("Attendees")
            .Multiple(true)
            .DataTextField("Text")
            .DataValueField("Value")
            .DataColorField("Color")
            .BindTo(new[] {
                    new { Text = "Alex", Value = 1, Color = "#f8a398" },
                    new { Text = "Bob", Value = 2, Color = "#51a0ed" },
                    new { Text = "Charlie", Value = 3, Color = "#56ca85" }
            });
    })
    .DataSource(d => d
        .Custom()
        .Batch(true)
        .Schema(schema => schema
            .Model(m =>
            {
                m.Id(f => f.MeetingID);
                m.Field("title", typeof(string)).DefaultValue("No title").From("Title");
                m.Field("start", typeof(DateTime)).From("Start");
                m.Field("end", typeof(DateTime)).From("End");
                m.Field("description", typeof(string)).From("Description");
                m.Field("recurrenceID", typeof(int)).From("RecurrenceID");
                m.Field("recurrenceRule", typeof(string)).From("RecurrenceRule");
                m.Field("recurrenceException", typeof(string)).From("RecurrenceException");
                m.Field("isAllDay", typeof(bool)).From("IsAllDay");
                m.Field("startTimezone", typeof(string)).From("StartTimezone");
                m.Field("endTimezone", typeof(string)).From("EndTimezone");
            })
        )
        .Transport(transport => transport
            .Read(read => read.Url("https://demos.telerik.com/service/v2/core/meetings"))
            .Create(create => create.Url("https://demos.telerik.com/service/v2/core/meetings/create").Type(HttpVerbs.Post).ContentType("application/json"))
            .Destroy(destroy => destroy.Url("https://demos.telerik.com/service/v2/core/meetings/destroy").Type(HttpVerbs.Post).ContentType("application/json"))
            .Update(update => update.Url("https://demos.telerik.com/service/v2/core/meetings/update").Type(HttpVerbs.Post).ContentType("application/json"))
            .ParameterMap("parameterMap")
        )
    )
)
```

```JS script.js
    <script>
         var buttonGroup = `<span data-role='buttongroup' class='k-widget   k-button-group k-toolbar-button-group' role='group'   data-uid='f01bcb47-94d9-4c40-8e55-53a28b45134d'>
             <button class='k-button     k-toggle-button k-group-start    ' ref-view-day data-name='day'    data-uid='dda9916c-3486-4407-9a69-4d5acca5ab52'    data-parentuid='f01bcb47-94d9-4c40-8e55-53a28b45134d'  data-role='togglebutton' type='button' role='button' aria-disabled='false'   tabindex='-1' aria-pressed='false' data-group='views' ref-toolbar-tool>
                 <span class='k-button-text'>Day</span>
             </button>
             <button class='k-button   k-toggle-button      ' data-name='week' ref-view-week  data-uid='faac8830-48a5-4b51-9574-9a6c39166b45'    data-parentuid='f01bcb47-94d9-4c40-8e55-53a28b45134d'  data-role='togglebutton' type='button' role='button' aria-disabled='false'   tabindex='-1' aria-pressed='false' data-group='views' ref-toolbar-tool>
                 <span class='k-button-text'>Week</span>
             </button>
             <button class='k-button  k-toggle-button       k-selected' ref-view-month data-name='month'   data-uid='be7bd46b-e9db-49ee-9d1f-aaee385d1884'   data-parentuid='f01bcb47-94d9-4c40-8e55-53a28b45134d'     data-role='togglebutton' type='button' role='button' aria-disabled='false'  tabindex='-1' aria-pressed='true' data-group='views' ref-toolbar-tool>
                 <span class='k-button-text'>Month</span>
             </button>
             <button class='k-view-year k-button   k-toggle-button     ' data-name='year'    data-uid='d5aa93e5-ea56-48b7-a878-5f427722fb18'    data-parentuid='f01bcb47-94d9-4c40-8e55-53a28b45134d'  data-role='togglebutton' type='button' role='button' aria-disabled='false'   tabindex='-1' aria-pressed='false' data-group='views' ref-toolbar-tool>
                 <span class='k-button-text'>Year</span>
             </button>
             <button class='k-button     k-toggle-button    ' data-name='agenda' ref-view-agenda   data-uid='bb93961e-ebe4-4e7a-bbaa-8fc4b8d69a90'    data-parentuid='f01bcb47-94d9-4c40-8e55-53a28b45134d'  data-role='togglebutton' type='button' role='button' aria-disabled='false'   tabindex='-1' aria-pressed='false' data-group='views' ref-toolbar-tool>
                 <span class='k-button-text'>Agenda</span>
             </button>
             <button class='k-button   k-toggle-button      k-group-end ' ref-view-timeline data-name='timeline'    data-uid='f137d9d3-02be-47a9-8b3c-9f13513f8090'    data-parentuid='f01bcb47-94d9-4c40-8e55-53a28b45134d'  data-role='togglebutton' type='button' role='button' aria-disabled='false'   tabindex='-1' aria-pressed='false' data-group='views' ref-toolbar-tool>
                 <span class='k-button-text'>Timeline</span>
             </button>
       </span>`;


        $(document).ready(function () {
             $(".k-scheduler-mobile-views").replaceWith(buttonGroup);

             $("button[class*='k-view'] > .k-button-text").click(function (e) {
                 var scheduler = $("#scheduler").data("kendoScheduler");
                 var view = $(e.target).text().toLowerCase()

                 $(this).parent().addClass("k-selected");
                 $(this).parent().siblings().removeClass("k-selected");

                 switch(view){
                     case 'day':
                         scheduler.view("day")
                         break;
                      case 'month':
                         scheduler.view("month")
                         break;
                     case 'agenda':
                         scheduler.view("agenda")
                         break;
                     case 'week':
                         scheduler.view("week")
                         break;
                     case 'timeline':
                         scheduler.view("timeline")
                         break;
                     case 'year':
                         scheduler.view("year")
                         break;
                 }
             })
        })
        $(window).resize(function () {
            if (window.innerWidth < 1024) {
                $(".k-scheduler-mobile-views").replaceWith(buttonGroup);
            }
        })
        function parameterMap(options, operation) {
            if (operation !== "read" && options.models) {
                kendo.stringify(options.models);
            }
        }
    </script>
```

For the complete implementation of the suggested approach, refer to the following [Telerik REPL](https://netcorerepl.telerik.com/GRbPcElf56LgXM3126) example.

## More ASP.NET MVC Scheduler Resources

* [ASP.NET MVC Scheduler Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/scheduling/scheduler/overview)

* [ASP.NET MVC Scheduler Demos](https://demos.telerik.com/aspnet-mvc/scheduler/index)

* [ASP.NET MVC Scheduler Product Page](https://www.telerik.com/aspnet-mvc/scheduler)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Telerik REPL: Preserve the ButtonGroup View for Mobile Rendering in the Scheduler](https://netcorerepl.telerik.com/GRbPcElf56LgXM3126)

* [Client-Side API Reference of the Scheduler for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/scheduler)

* [Server-Side API Reference of the Scheduler for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/scheduler)

* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2023-backwards-compatibility)

* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
