Resources from Two Different Tables or Data Sources

I am running into a problem trying to have two different resources from different DataSources and Tables.

My Scheduler:


<SfSchedule TValue=ScheduleItem Height="calc(100vh - 8rem">
    <ScheduleTimeScale Interval="30" SlotCount="2"></ScheduleTimeScale>
    <ScheduleResources>
        <ScheduleResource TValue="int" TItem="Programs" Field="ProgramId" Title="Program" Name="Programs"
                          TextField="ProgramName" IdField="Id" ColorField="CalendarColor">
            <SfDataManager Url="api/programs" Adaptor="Adaptors.WebApiAdaptor"/>
        </ScheduleResource>
        <ScheduleResource TItem="User" TValue="string" Field="StaffId" Title="Staff" Name="Staff"
                          TextField="Name" IdField="Id" ColorField="CalendarColor" DataSource="@_users">
            <SfDataManager Url="api/users" Adaptor="Adaptors.WebApiAdaptor"/>
        </ScheduleResource>
    </ScheduleResources>
    <ScheduleEventSettings TValue="ScheduleItem" Query="@QueryData">
        <SfDataManager Url="https://localhost:5001/odata" Adaptor="Adaptors.ODataV4Adaptor"/>
        <ScheduleField>
            <FieldSubject Name="Title"/>
        </ScheduleField>
    </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>


The Result:

Screen Shot 2022-06-14 at 8.39.31 AM.png


When I don't have the Staff resource, the Program resource shows in the edit dialog and operates as it should. How do I get the two resources functioning?

Thank you!


3 Replies

RM Ruksar Moosa Sait Syncfusion Team June 15, 2022 12:26 PM UTC

Hi Judi,


We have checked on your shared codes and suspect that defining both the DataManager and Datasource values has caused the reported issue. Hence, we suggest you either define the DataManager or assign the DataSource value for the resource to overcome this issue. Also, make sure that the service URL is properly assigned to DataManager for the resources.


<ScheduleResources>
        <ScheduleResource TValue="int" TItem="Programs" Field="ProgramId" Title="Program" Name="Programs"
                          TextField="ProgramName" IdField="Id" ColorField="CalendarColor">
            <SfDataManager Url="api/programs" Adaptor="Adaptors.WebApiAdaptor"/>
        </ScheduleResource>
        <ScheduleResource TItem="User" TValue="string" Field="StaffId" Title="Staff" Name="Staff"
                          TextField="Name" IdField="Id" ColorField="CalendarColor" DataSource="@_users">
            <SfDataManager Url="api/users" Adaptor="Adaptors.WebApiAdaptor"/>
</ScheduleResource>


Let us know if you need assistance.


Regards,

Ruksar Moosa Sait



JS Judi Smith June 15, 2022 04:04 PM UTC

Ruskar,

I have discovered the initial problem. The Scheduler was looking for a parent-child relationship with a Group Id. 

I am now running into another issue: When I have both staff and programs showing on the editor, when I select a program from the dropdown, I get an error:

System.InvalidCastException: Specified cast is not valid.
   at Syncfusion.Blazor.Schedule.Internal.ResourceRenderer`2.<OnDropDownChange>d__32[[StudioPlanner.Shared.Models.Programs, StudioPlanner.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[System.Int32, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()

but without adding the staff resource to the Scheduler, the Program selection works as expected.


Also, I now have several other questions:

  1. Is it possible to have multiple Resources without a parent-child relationship?  In my case I need to assign a Program and (multiple)Staff. The staff and the program do not have a relationship. Any staff may be assigned to any program.
  2. Is it possible to have multiple resources assigned to an appointment and have them show as just one event on the calendar? For example, if I assign multiple staff to one appointment, can it show as just one event on the calendar as opposed to one event per staff member?

Thanks



RV Ravikumar Venkatesan Syncfusion Team June 17, 2022 10:11 AM UTC

Hi Judi,


Q1: I have both staff and programs showing on the editor, when I select a program from the dropdown, I get an error

To overcome the problem we suggest you use the same type for both parent and child-level resources as shown in the below code snippet.


[ResourceGrouping.razor]

<SfSchedule TValue=ScheduleItem Height="calc(100vh - 8rem)">

    <ScheduleResources>

        <ScheduleResource TValue="string" TItem="Programs" Field="ProgramId" Title="Program" Name="Programs" DataSource="@programs" TextField="ProgramName" IdField="Id" ColorField="CalendarColor">

        </ScheduleResource>

        <ScheduleResource TValue="string" TItem="User" Field="StaffId" Title="Staff" Name="Staff" GroupIDField="GroupID" TextField="Name" IdField="Id" ColorField="CalendarColor" DataSource="@users">

        </ScheduleResource>

    </ScheduleResources>

</SfSchedule>


Q2: Is it possible to have multiple Resources without a parent-child relationship?

Q3: Is it possible to have multiple resources assigned to an appointment and have them show as just one event on the calendar?

You can achieve your requirement by adding custom fields for Program and Staff in the editor window using editorTemplate without enabling resources and grouping in the Schedule. So, if you add an appointment you can choose multiple staff under a program and it will be rendered as a single appointment.


[Index.razor]

<SfSchedule TValue=ScheduleItem Height="calc(100vh - 8rem)">

    <ScheduleTemplates>

        <EditorTemplate>

            <input type="hidden" name="Id" class="e-field" value="@((context as ScheduleItem).Id)" />

            <table class="custom-event-editor" width="100%" cellpadding="5">

                <tbody>

                    <tr>

                        <td class="e-textlabel">Program</td>

                        <td class="dropdown" colspan="4">

                            <SfDropDownList TValue="int?" TItem="ProgramFields" ID="Program" DataSource="@programData" Placeholder="Choose Program" @bind-Value="@((context as ScheduleItem).Program)">

                                <DropDownListFieldSettings Value="Id" Text="Text"></DropDownListFieldSettings>

                            </SfDropDownList>

                        </td>

                    </tr>

                    <tr>

                        <td class="e-textlabel">Staffs</td>

                        <td class="dropdown" colspan="4">

                            <SfMultiSelect ID="Staffs" TValue="string[]" TItem="StaffFields" Placeholder="Select Staffs" DataSource="@staffsData" @bind-Value="@((context as ScheduleItem).Staffs)">

                                <MultiSelectFieldSettings Text="Name" Value="Value"></MultiSelectFieldSettings>

                            </SfMultiSelect>

                        </td>

                    </tr>

                </tbody>

            </table>

        </EditorTemplate>

    </ScheduleTemplates></SfSchedule>


Kindly let us know if you need any further assistance.


Regards,

Ravikumar Venkatesan


Attachment: syncfusionblazorschedulewitheditortemplate_2e4af96f.zip

Loader.
Up arrow icon