This is a migrated thread and some comments may be shown as answers.

bind Scheduler Resource using DataSource controller action NOT working

5 Answers 884 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Future Link IT
Top achievements
Rank 1
Future Link IT asked on 09 Mar 2018, 09:48 PM

Scheduler Resource Binding using DataSource not displaying Employee.  Where are the examples?  I need an example that doesn't use BindTo.  Also where are the Asp.Net Core 2 examples?  all are for Asp.net 1

 

@(Html.Kendo().Scheduler<SalonWeb.Models.TimeBlock>()
    .Name("scheduler")
    .Date(DateTime.Now)
    .StartTime(DateTime.Now)
    .Height(600)
    .MajorTick(60)
    .Views(views =>
    {
        views.DayView();
        views.WeekView();
        views.MonthView();
    })
    .Resources(resource =>
    {
        //reading but not displaying
        resource.Add(m => m.Employee)  //employee object
            .Title("Employee") //descriptive title
            .DataTextField("Name") //property in Employee Object
            .DataValueField("Id") //property in Employee Object
            .DataColorField("Color") //property in Employee Object
            .DataSource(ds => ds
                .Read("Read", "Employees") //Read function in Employee controller
            );
    })
    .DataSource(d => d
        .Model(m => {
            m.Id(f => f.Id);
            m.Field(f => f.Title).DefaultValue("No title");
            m.Field(f => f.Employee);
        })
        .Read("Read", "TimeBlocks")
        .Create("Create", "TimeBlocks")
        .Update("Update", "TimeBlocks")
        .Destroy("Delete", "TimeBlocks")
    )
)

TimeBlock controller 

public async Task<IActionResult> Create([DataSourceRequest] DataSourceRequest request, TimeBlock timeBlock)
        {
            if (ModelState.IsValid)
            {
                _context.Add(timeBlock);
                await _context.SaveChangesAsync();
            }
            return Json(await new[] { timeBlock }.ToDataSourceResultAsync(request, ModelState));
        }


Employee Controller

public async Task<IActionResult> Read([DataSourceRequest] DataSourceRequest request)
        {
            return Json(await _context.Employee.ToDataSourceResultAsync(request));
        }

5 Answers, 1 is accepted

Sort by
0
Neli
Telerik team
answered on 13 Mar 2018, 12:02 PM
Hello,

I have replied in the support thread regarding the same issue. I will paste my last reply below, as it could be helpful to the other users in the Forum.
I would suggest you to keep the conversation in a single thread. 

The Demo that I have sent you a link is demonstrating the basic usage of Scheduler Resources. The remote data binding of the Resources could not be observed in the Demo, but it is giving an overview of the Resources. For this reason I have prepared the sample project that is attached to my previous reply. Below is the configuration that you will find in Views -> Home -> Index.cshtml
Copy Code
@(Html.Kendo().Scheduler<SchedulerBasicCore.Models.ScheduleViewModel>()
    .Name("scheduler")
    .Date(DateTime.Now)
    .StartTime(new DateTime(2017, 1, 1, 6, 00, 00))
    .Height(600)
    .Width(800)
    .Views(views =>
    {
        views.MonthView();
        views.DayView();
        views.WeekView();
        views.WorkWeekView(workWeekView =>
        {
            workWeekView.Selected(true);
        });
    })
    .Timezone("Etc/UTC")
    .DataSource(d => d
        .Events(e => e.Error("onError"))
        .Model(m =>
        {
            m.Id(f => f.EventId);
            m.Field(f => f.Title).DefaultValue("No title");
            m.RecurrenceId(f => f.RecurrenceId);
        })
        .Read(read => read.Action("Schedules_Read", "Scheduler"))
        .Create(create => create.Action("Schedules_Create", "Scheduler"))
        .Update(update => update.Action("Schedules_Update", "Scheduler"))
        .Destroy(destroy => destroy.Action("Schedules_Destroy", "Scheduler"))
    )
    .Resources(resource =>
    {
        resource.Add(m => m.RoomID)
            .Title("Room")
            .DataSource(ds => ds
                    .Custom()                   
                    .Transport(transport => transport.Read(read => read.Action("Resources", "Scheduler")))
                    .Schema(schema => schema                      
                        .Data("Data")
                        .Total("Total")
                        .Errors("Errors")
                        .Model(model =>
                        {
                            model.Id("Value");
                            model.Field("Value", typeof(int));
                            model.Field("Text", typeof(string));
                            model.Field("Color", typeof(string));
                        })
                    )
                )
            .DataTextField("Text")
            .DataValueField("Value")
            .DataColorField("Color");
    })
)

Here is the respective end point for populating the Resources (SchedulerController.cs). 

Copy Code
public JsonResult Resources([DataSourceRequest] DataSourceRequest request)
 {
List<Room> rooms = new List<Room>() {
new Room(){Value = 1, Color = "#1c9ec4", Text = "Room 1"},
new Room(){Value = 2, Color = "#ff7663", Text = "Room 2" },
new Room(){Value = 3, Color = "purple", Text = "Room 3"}
};
return Json(rooms.ToDataSourceResult(request));
}

Note, that the create, update and destroy end points for the Scheduler dataSource are not implemented. 


Regards,
Neli
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Evan
Top achievements
Rank 1
answered on 09 Mar 2020, 11:44 AM

Hi there!

When I implement this example the resources passed through to the CRUD methods are null. I can see the list but its a list of null.

See here for details https://stackoverflow.com/questions/60599258/list-of-attendees-is-returning-list-of-nulls-in-crud-methods-for-telerik-for-mvc

Any ideas on this one would be greatly appreciated.

0
Martin
Telerik team
answered on 12 Mar 2020, 09:07 AM

Hello Evan,

I tested the implementation in the example from my colleague and it works as expected. Could you please modify the attached project to reproduce the issue you are experiencing? I will then happily assist you.

Looking forward to your reply.

Regards,
Martin
Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
0
Tim
Top achievements
Rank 1
answered on 12 Mar 2020, 09:24 AM
Telerik - Can you provide a tag helper example please?
0
Martin
Telerik team
answered on 17 Mar 2020, 09:23 AM

Hello Tim,

In the process of creating a tag helper example, I discovered that the DataSourceTagHelper is not available for the Scheduler TagHelper resources. I have logged the behavior as a bug and it will be handled with a high priority. Until the fix is available, I am afraid there is no way to set remote resources for the Scheduler TagHelper.

Let me know if you have any questions

Regards,
Martin
Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
Tags
Scheduler
Asked by
Future Link IT
Top achievements
Rank 1
Answers by
Neli
Telerik team
Evan
Top achievements
Rank 1
Martin
Telerik team
Tim
Top achievements
Rank 1
Share this question
or