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

Pass parameters to SignalR read method

10 Answers 1046 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Bernd
Top achievements
Rank 2
Bernd asked on 28 Jun 2016, 05:21 PM

Hi all.

I am looking for a way to pass filter criteria to my read method. E.g. the resource list, the startdate and the end date.
There is a thread solving this for a SignalR bound grid. But I don't see how to do it with the scheduler

Any ideas?

Kind regards

Bernd

10 Answers, 1 is accepted

Sort by
0
Accepted
Vladimir Iliev
Telerik team
answered on 29 Jun 2016, 08:54 AM
Hello,

Currently we have no such example which we can provide, however the same approach can be used for the Scheduler as both widgets share same base DataSource. If you need to send additional parameters than you can define custom "ParameterMap" function and extend the "MyDataSourceRequest" object on the server side to include the desired additional parameters. Please check the example below:

Custom ParameterMap:
.Transport(tr => tr
    .ParameterMap("customParameterMap")
    .Promise("hubStart")

function customParameterMap(data) {
 
    if (operation === "read") {
        var scheduler = $("#scheduler").data("kendoScheduler");
        var result = {
            start: scheduler.view().startDate(),
            end: scheduler.view().endDate(),
            //example filter:
            filter: {
                "logic": "and",
                "filters": [{
                    "logic": "and",
                    "filters": [{
                        "field": "RoomID",
                        "operator": "eq",
                        "value": 10
                    }]
                }]
            }
        }
        return result;
    }
 
    return data;
}

Server side:
//Extending the MyDataSourceRequest from Kendo DynamicLinq:
public class MyDataSourceRequestExtended : MyDataSourceRequest
{
    public DateTime start { get; set; }
    public DateTime end { get; set; }
}


public DataSourceResult Read(MyDataSourceRequestExtended request)
{
    return taskService.Read()
        //fiter the events by the provided start / end times
        .Where(t => (t.Start >= request.start || t.Start <= request.start) && t.Start <= request.end && t.End >= request.start && (t.End >= request.end || t.End <= request.end) || t.RecurrenceRule != null)
        //apply the other filters
        .ToDataSourceResult(request.Take, request.Skip, request.Sort, request.Filter, request.Aggregates);
}

Regards,
Vladimir Iliev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Bernd
Top achievements
Rank 2
answered on 29 Jun 2016, 11:38 AM

Dear Vladimir.

Besides the missing operation parameter in your function customParameterMap this works.

Thank you
Bernd

0
Bernd
Top achievements
Rank 2
answered on 01 Jul 2016, 04:43 AM

Dear Vladimir.

Having managed to submit the parameters I now get an exception.

"Uncaught TypeError: Cannot read property 'getTimezoneOffset' of undefined"

It seems the returned data isn't parsed correctly. As you can see in the attached screenshot the model contains a field "Data" which contains my 25 events and the other fields are not initialized.

Most probably my scheduler configuration is wrong, but I don't see what could be wrong.

01.@(Html.Kendo().Scheduler<CalendarEventViewModel>()
02.    .Name(componentName: "scheduler")
03.    .Date(DateTime.Today)
04.    .Height(height: 800)
05.    .AllDaySlot(allDaySlot: false)
06.    .Views(views => {
07.        views.DayView(v => v.Selected(isSelected: true));
08.        views.WeekView();
09.        views.WorkWeekView();
10.        views.AgendaView();
11.    })
12.    .Editable(editable => { editable.TemplateName(name: "CalendarEventEditorTemplate"); })
13.    .Timezone("Etc/UTC")
14.    .Events(e => {
15.        e.Save(handler: "onSchedulerSave");
16.        e.Edit(handler: "onSchedulerEdit");
17.        e.MoveStart(handler: "onSchedulerMoveStart");
18.        e.MoveEnd(handler: "onSchedulerMoveEnd");
19.        e.ResizeStart(handler: "onSchedulerResizeStart");
20.        e.ResizeEnd(handler: "onSchedulerResizeEnd");
21.        e.DataBound(handler: "onSchedulerDataBound");
22.    })
23.    .Group(g => g.Resources(names: "Resources"))
24.    .Resources(res => {
25.        res.Add(m => m.WorkplaceId)
26.        .Name(value: "Resources")
27.        .Title(this.LocalResources(key: "Resources.Title"))
28.        .DataTextField(field: "Text")
29.        .DataValueField(field: "Value")
30.        .DataColorField(field: "Color")
31.        .DataSource(ds => ds.Read(read => read.Route(ResourceControllerRoute.GetRead, new RouteValueDictionary { { "culture", UICulture.ToLower() } }))); })
32.    .DataSource(ds => ds
33.            .SignalR()
34.            .AutoSync(enabled: true)
35.            .ServerFiltering(enabled: true)
36.            .ServerPaging(enabled: true)
37.            .Events(ev => ev.Push(handler: "onPush"))
38.            .Transport(tr => tr
39.                .ParameterMap(handler: "addSchedulerParameters")
40.                .Promise(handler: "hubStart")
41.                .Hub(handler: "schedulerHub")
42.                .Client(c => c
43.                    .Read(method: "readRanged")
44.                    .Create(method: "create")
45.                    .Update(method: "update")
46.                    .Destroy(method: "destroy"))
47.                .Server(s => s
48.                    .Read(method: "readRanged")
49.                    .Create(method: "create")
50.                    .Update(method: "update")
51.                    .Destroy(method: "destroy"))
52.            )
53.            .Schema(schema => schema
54.                .Model(m => {
55.                    m.Id(f => f.Id);
56.                    m.Field(f => f.WorkplaceId);
57.                    m.Field(f => f.Start);
58.                    m.Field(f => f.End);
59.                    m.Field(f => f.IsAllDay);
60.                    m.Field(f => f.Title).DefaultValue(this.LocalResources(key: "OperationViewModel.Title.DefaultValue"));
61.                    m.Field(f => f.RecurrenceRule);
62.                    m.Field(f => f.Description);
63.                    //m.RecurrenceId(f => f.Recurrence);
64.                })
65.            )
66.            .Events(e => e.Error(handler: "error_handler"))
67.    ).Deferred()
68.)

Any ideas what's wrong here?

Regards

Bernd

0
Vladimir Iliev
Telerik team
answered on 01 Jul 2016, 06:06 AM
Hello Bernd,

When you modify the response format you should modify the DataSource "Schema.Data" option which tells in which field of the response the records are held. Please check the example below:


.Schema(schema => schema
    .Data("Data")
    .Total("Total")

Regards,
Vladimir Iliev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Bernd
Top achievements
Rank 2
answered on 01 Jul 2016, 08:34 AM

Thank you for your fast reply.

The array is now converted. But the error is still the same. The debugger shows me the property names are PascalCase in the model. How can I tell the widget or the MVC wrapper to map the properties correctly?

0
Vladimir Iliev
Telerik team
answered on 04 Jul 2016, 07:18 AM
Hi Bernd,

This is a bit strange - the MVC wrapper should automatically map the the server model properties to the one required by the Scheduler. Could you please provide runable example where the issue is reproduced? This would help us pinpoint the exact reason for current behavior. 

Regards,
Vladimir Iliev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Bernd
Top achievements
Rank 2
answered on 04 Jul 2016, 11:42 AM

Hi Vladimir.

You already have one. Your own example.

Now I know why you used

model.Field("start", typeof(DateTime)).From("Start");

in your example instead of just

model.Field("Start");

Would be nice if the MVC wrapper could handle this automagically as I expect it from using the ajax version. Maybe there is a difference in handlig

Kind regards

Bernd

0
Vladimir Iliev
Telerik team
answered on 05 Jul 2016, 07:24 AM
Hello Bernd,

Apologize that I missed this in the previously provided code samples - the SignalR builder inherits from the CustomDataSource builder and therefor it requires manually describing the field mapping. I would suggest to share your idea at KendoUI UserVoice to allow other users vote for it. Most voted ideas are included in next Kendo UI releases. 

Regards,
Vladimir Iliev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Bernd
Top achievements
Rank 2
answered on 05 Jul 2016, 07:42 AM
Done: http://kendoui-feedback.telerik.com/forums/127393-kendo-ui-feedback/suggestions/15083931-signalr-map-the-required-scheduler-properties-in
0
Christine
Top achievements
Rank 1
Veteran
answered on 09 Oct 2020, 09:10 PM
I just wanted to thank you for all of the information you provided in this post.  I recently submitted a ticket for help with sending parameters on a signalr grid and also needed help with server paging and was told that the server paging couldn't be done and that i needed to send parameters through the hub url. Fortunately i was able to get everything working using the transports parametermap handler and i also found another sample online that showed me how to do the server paging - phew!  I wanted to suggest posting examples of how to do this on the asp.net core mvc grid signalr demo screen.  I spent days figuring this out and i am sure there are others out there that could benefit from some extra online documentation/demos as well.
Tags
Scheduler
Asked by
Bernd
Top achievements
Rank 2
Answers by
Vladimir Iliev
Telerik team
Bernd
Top achievements
Rank 2
Christine
Top achievements
Rank 1
Veteran
Share this question
or