Add / Remove Resources


Hi,

We've found this functionality below (https://www.syncfusion.com/kb/5550/how-to-dynamically-add-remove-the-resources-in-the-schedule-control) but how can we achieve this functionality using Blazor Scheduler ?


5 Replies

AK Alagumeena Kalaiselvan Syncfusion Team March 27, 2020 12:34 PM UTC

Hi Alex, 

Greetings from Syncfusion support! 

We have checked your reported case “How to add/remove resource dynamically” and you can achieve this case in blazor by using AddResource/RemoveResource methods for add/remove resources respectively. We have prepared a sample for your reference which can be downloaded from the below link. 

  

Kindly get back to us, If you need further assistance. 

Regards 
Alagumeena.K 



AL Alex March 27, 2020 12:38 PM UTC

Hi,

Many thanks for the reply and sample code - we'll take a look.  

More awesome support from Syncfusion!

Regards,
Alex


VM Vengatesh Maniraj Syncfusion Team March 30, 2020 04:42 AM UTC

Hi Alex, 
 
You are most welcome. 
 
Please get in touch with us if you would require any further assistance. 
  
Regards,  
Vengatesh 



LA lamia July 7, 2023 08:40 AM UTC

Hello how do i acheieve the smae if the resources are grouped ?

thank you



VS Venkateshwaran Saravanakumar Syncfusion Team July 10, 2023 02:29 PM UTC

Hi Alex,     

We suspect that you want to remove/add parent level resources, you can achieve this by using the below shared snippet. If we misunderstood your requirement, provide us with more details about your requirement. 

@using Syncfusion.Blazor.Schedule

@using Syncfusion.Blazor.Buttons

 

<SfSchedule @ref="ScheduleRef" TValue="AppointmentData" Height="550px" @bind-SelectedDate="@CurrentDate">

    <ScheduleGroup Resources="@Resources"></ScheduleGroup>

    <ScheduleResources>

        <ScheduleResource TItem="ResourceData" TValue="int" DataSource="@RoomData" Field="RoomId" Title="Room" Name="Rooms" TextField="RoomText" IdField="Id" ColorField="RoomColor" AllowMultiple="false"></ScheduleResource>

        <ScheduleResource TItem="ResourceData" TValue="int[]" DataSource="@OwnersData" Field="OwnerId" Title="Owner" Name="Owners" TextField="OwnerText" IdField="Id" GroupIDField="OwnerGroupId" ColorField="OwnerColor" AllowMultiple="true"></ScheduleResource>

    </ScheduleResources>

    <ScheduleEventSettings DataSource="@DataSource"></ScheduleEventSettings>

    <ScheduleViews>

        <ScheduleView Option="View.Day"></ScheduleView>

        <ScheduleView Option="View.Week"></ScheduleView>

        <ScheduleView Option="View.WorkWeek"></ScheduleView>

        <ScheduleView Option="View.Month"></ScheduleView>

        <ScheduleView Option="View.Agenda"></ScheduleView>

    </ScheduleViews>

</SfSchedule>

 

<div class="col-lg-3 property-section">

    <table id="property" title="Show / Hide Resource" style="width: 100%">

        <tbody>

            <tr style="height: 50px">

                <td style="width: 100%">

                    <SfCheckBox TChecked="bool" @bind-Checked="@IsChecked1" ValueChange="@(e => OnChange(e, 1))" Disabled="true" Label="ROOM 1" CssClass="personal"></SfCheckBox>

                </td>

            </tr>

            <tr style="height: 50px">

                <td style="width: 100%">

                    <SfCheckBox TChecked="bool" @bind-Checked="@IsChecked2" ValueChange="@(e => OnChange(e, 2))" Label="ROOM 2" CssClass="company"></SfCheckBox>

                </td>

            </tr>

            <tr style="height: 50px">

                <td style="width: 100%">

                    <SfCheckBox TChecked="bool" @bind-Checked="@IsChecked3" ValueChange="@(e => OnChange(e, 3))" Label="ROOM 3" CssClass="birthday"></SfCheckBox>

                </td>

            </tr>

        </tbody>

    </table>

</div>

@code {

 

    SfSchedule<AppointmentData> ScheduleRef;

    DateTime CurrentDate = new DateTime(2023, 6, 1);

    private bool IsChecked1 { get; set; } = true;

    private bool IsChecked2 { get; set; } = false;

    private bool IsChecked3 { get; set; } = false;   

 

 

    public string[] Resources { get; set; } = { "Rooms", "Owners" };

    public List<ResourceData> RoomData { get; set; } = new List<ResourceData>

    {

        new ResourceData{ RoomText = "ROOM 1", Id = 1, RoomColor = "#cb6bb2" }

    };

    public List<ResourceData> OwnersData { get; set; } = new List<ResourceData>

    {

        new ResourceData{ OwnerText = "Nancy", Id = 1, OwnerGroupId = 1, OwnerColor = "#ffaa00" },

        new ResourceData{ OwnerText = "Steven", Id = 2, OwnerGroupId = 2, OwnerColor = "#f8a398" },

        new ResourceData{ OwnerText = "Michael", Id = 3, OwnerGroupId = 3, OwnerColor = "#7499e1" }

    };

    List<AppointmentData> DataSource = new List<AppointmentData>

     {

        new AppointmentData { Id = 1, Subject = "Meeting", StartTime = new DateTime(2023, 6, 1, 9, 30, 0) , EndTime = new DateTime(2023, 6, 1, 11, 0, 0), OwnerId = 1, RoomId = 1 }

    };

 

 

 

    public void OnChange(Syncfusion.Blazor.Buttons.ChangeEventArgs<bool> args, int value)

    {

        List<ResourceData> CalendarCollections = new List<ResourceData> {

         new ResourceData{ RoomText = "ROOM 1", Id = 1, RoomColor = "#cb6bb2" },

        new ResourceData{ RoomText = "ROOM 2", Id = 2, RoomColor = "#56ca85" },

         new ResourceData{ RoomText = "ROOM 3", Id = 3, RoomColor = "#56ca85" },         

      };

        var resourceData = CalendarCollections.Find(v => v.Id == value);

        if (args.Checked)

        {

            ScheduleRef.AddResource<ResourceData>(new List<ResourceData> { resourceData }, "Rooms", value - 1);

        }

        else

        {

            ScheduleRef.RemoveResource<int>(new List<int> { value }, "Rooms");

        }

    }

 



Regards,
Venkatesh


Attachment: AddRemoveResource_7d55e4a7.zip

Loader.
Up arrow icon