Back to Devexpress

DxSchedulerDataStorage.ResourcesSource Property

blazor-devexpress-dot-blazor-dot-dxschedulerdatastorage-b9517a02.md

latest9.6 KB
Original Source

DxSchedulerDataStorage.ResourcesSource Property

Specifies a data source for the appointment’s resources.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public IEnumerable ResourcesSource { get; set; }

Property Value

TypeDescription
IEnumerable

A collection of objects with resource data.

|

Remarks

Follow the steps below to add and assign resources to Scheduler appointments:

  1. Use the constructor without parameters to create a DxSchedulerDataStorage object. See the DxSchedulerAppointmentMappings class description for additional information.
  2. Declare a class that stores resource options (for instance, ResourceObject).
  3. Create a collection of resource source objects (ResourceObject class instances) and define their options:
  • Id - Specifies the resource’s unique identifier.
  • Caption - Specifies the resource’s caption.
  • Color - Specifies the resource’s color. To apply this color to all appointments that correspond to the resource, remove appointment labels.
  • BackgroundCssClass - Specifies the CSS class applied to the resource’s background (the background color, background image, border color, and so on). Note that the Color property value overrides the background color specified in the CSS class.
  • TextCssClass - Specifies the CSS class applied to the text of appointments that correspond to the resource.
  1. Assign the newly created collection to the storage’s ResourcesSource property to fill the storage with a collection of data objects. The Scheduler generates a resource item (DxSchedulerResourceItem) for each item in this collection.
  2. Assign a new DxSchedulerResourceMappings object to the DxSchedulerDataStorage.ResourceMappings property. In this object, map the data source fields to appointment properties.
  3. Optional. Group appointments by resource. To do this, set the Scheduler’s GroupType property to SchedulerGroupType.Resource.
razor
<DxScheduler StartDate="@DateTime.Today"
             DataStorage="@DataStorage"
             GroupType="SchedulerGroupType.Resource"
             ResourceColorInHeaderVisible="true">
    <Views>
        <DxSchedulerDayView DayCount="3"
                            TimeScale="@(new TimeSpan(1,0,0))"
                            WorkTime="new DxSchedulerTimeSpanRange(TimeSpan.FromHours(9), TimeSpan.FromHours(18))"
                            VisibleTime="new DxSchedulerTimeSpanRange(TimeSpan.FromHours(8), TimeSpan.FromHours(19))"
                            TimeIndicatorVisibility="SchedulerTimeIndicatorVisibility.Never">
        </DxSchedulerDayView>
        <DxSchedulerWeekView ShowWorkTimeOnly="true" />
        <DxSchedulerWorkWeekView ShowWorkTimeOnly="true" />
        <DxSchedulerTimelineView />
    </Views>
</DxScheduler>

@code {
    DxSchedulerDataStorage DataStorage = new DxSchedulerDataStorage() {
        AppointmentsSource = AppointmentCollection.GetAppointments(),
        AppointmentMappings = new DxSchedulerAppointmentMappings() {
            Type = "AppointmentType",
            Start = "StartDate",
            End = "EndDate",
            Subject = "Caption",
            AllDay = "AllDay",
            Location = "Location",
            Description = "Description",
            LabelId = "Label",
            StatusId = "Status",
            RecurrenceInfo = "Recurrence",
            ResourceId = "ResourceId"
        },
        ResourcesSource = ResourceCollection.GetResources(),
        ResourceMappings = new DxSchedulerResourceMappings() {
            Id = "Id",
            Caption = "Name",
            Color = "Color",
            BackgroundCssClass = "BackgroundCss",
            TextCssClass = "TextCss"
        }
    };
}
csharp
public class Appointment {
    public Appointment() { }
    public int AppointmentType { get; set; }
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }
    public string Caption { get; set; }
    public string Description { get; set; }
    public string Location { get; set; }
    public int? Label { get; set; }
    public int Status { get; set; }
    public bool AllDay { get; set; }
    public string Recurrence { get; set; }
    public int? ResourceId { get; set; }
}
csharp
public static partial class AppointmentCollection {
    public static List<Appointment> GetAppointments() {
        DateTime date = DateTime.Now.Date;
        var dataSource = new List<Appointment>() {
            new Appointment {
                Caption = "Install New Router in Dev Room",
                StartDate = date + (new TimeSpan(0, 10, 0, 0)),
                EndDate = date + (new TimeSpan(0, 12, 0, 0)),
                Status = 1,
                ResourceId = 0
            },
            new Appointment {
                Caption = "Upgrade Personal Computers",
                StartDate = date + (new TimeSpan(0, 13, 0, 0)),
                EndDate = date + (new TimeSpan(0, 14, 30, 0)),
                Status = 1,
                ResourceId = 0
            },
            // ...            
            new Appointment {
                Caption = "Final Budget Review",
                StartDate = date + (new TimeSpan(0, 13, 0, 0)),
                EndDate = date + (new TimeSpan(0, 15, 0, 0)),
                Status = 1,
                ResourceId = 1
            },
            new Appointment {
                Caption = "Install New Database",
                StartDate = date + (new TimeSpan(0, 9, 45, 0)),
                EndDate = date + (new TimeSpan(1, 11, 15, 0)),
                Status = 1,
                ResourceId = 1
            },
            // ...
        };
        return dataSource;
    }
}
csharp
public class ResourceObject {
    public int Id { get; set; }
    public string Name { get; set; }
    public System.Drawing.Color Color { get; set; }
    public string TextCss { get; set; }
    public string BackgroundCss { get; set; }
}
csharp
public static partial class ResourceCollection {
    public static List<ResourceObject> GetResources() {
        var dataSource = new List<ResourceObject>() {
            new ResourceObject() { Id=0 , Name="John Heart", TextCss="text-white",
                                   BackgroundCss="dxbl-green-color", 
                                   /*Color = System.Drawing.Color.Green*/ },
            new ResourceObject() { Id=1 , Name="Samantha Bright", TextCss="text-white",
                                   BackgroundCss="dxbl-orange-color", 
                                   /*Color = System.Drawing.Color.Orange*/ },
            new ResourceObject() { Id=2 , Name="Arthur Miller", TextCss="text-white",
                                   BackgroundCss="dxbl-purple-color", 
                                   /*Color = System.Drawing.Color.Purple*/ },
        };
        return dataSource;
    }
}

If you do not need to display all of the resources from the data source, use the VisibleResourcesDataSource property to specify visible resources.

Run Demo: Scheduler - Resources

YouTube video

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ResourcesSource property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

blazor-scheduler-custom-form/CS/DxBlazorApplication1/Components/Pages/Index.razor.cs#L71

csharp
Storage.AppointmentsSource = await AptService.GetAppointmentsAsync();
Storage.ResourcesSource = await ResService.GetResourcesAsync();
Storage.AppointmentLabelsSource = await LblService.GetLabelsAsync();

See Also

DxSchedulerDataStorage Class

DxSchedulerDataStorage Members

DevExpress.Blazor Namespace