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
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
Dear Vladimir.
Besides the missing operation parameter in your function customParameterMap this works.
Thank you
Bernd
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
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
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?
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
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
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