The problem I am having right now actually comes from the slightly different ways things work, in the other calendar I was using, when you wanted to delete something, I could get the ID, send that to the controllers, then to the stored procedures in SQL Server to delete that specific item. I would very much prefer to continue this line of coding.,
So as part of the demo:
transport: {
read: {
dataType:
"jsonp"
},
update: {
dataType:
"jsonp"
},
create: {
dataType:
"jsonp"
},
destroy: {
dataType:
"jsonp"
},
parameterMap:
function
(options, operation) {
if
(operation !==
"read"
&& options.models) {
return
{models: kendo.stringify(options.models)};
}
I havent actually used a lot of the datasources for this kind of thing just yet, typically we'd actually just use the datasource to display data, then get the ID out of the data source, and do something with that (delete, edit, etc)
So, little help?
14 Answers, 1 is accepted
im using WebAPI Controllers, so is there a dataitem that I can reference from the event items?
The parameterMap function is responsible for sending data to the server-side. The updated events are available in the options.models field (if batch mode is enabled). If batch mode is disabled all event fields are available as fields of the "options" parameter.
Here is how you can pass the id:
parameterMap: function(options) {
return {
eventId: options.models[0].id
};
}
If you want to send it as JSON:
parameterMap: function(options) {
return kendo.stringify({
eventId: options.models[0].id
});
}
Atanas Korchev
Telerik
$(
"#calendar"
).kendoScheduler({
batch:
true
,
height: 600,
views: [
"day"
,
"week"
,
{ type:
"month"
, selected:
true
},
"agenda"
],
dataSource: {
transport: {
read: {
url: BaseAPI +
"/NewFullCalendar"
,
dataType:
"json"
},
update: {
dataType:
"jsonp"
},
create: {
dataType:
"jsonp"
},
destroy: {
url: BaseAPI +
"/Calendar"
,
datatype:
"json"
,
},
parameterMap:
function
(options, operation) {
switch
(operation) {
case
"read"
:
return
{ location: locationID };
break
;
case
"update"
:
return
break
;
case
"create"
:
return
break
;
case
"destroy"
:
return
kendo.stringify({ location: locationID, ID: options.models[0].id });
break
;
}
}
},
schema: {
model: {
id:
"id"
,
fields: {
ID: { from:
"ID"
, type:
"number"
},
title: { from:
"title"
, defaultValue:
"No title"
, validation: { required:
true
} },
start: { type:
"date"
, from:
"start"
},
end: { type:
"date"
, from:
"end"
},
description: { from:
"Content"
},
recurrenceId: { from:
"recurrenceID"
},
recurrenceRule: { from:
"recurrenceRule"
},
recurrenceException: { from:
"recurrenceException"
},
isAllDay: { type:
"boolean"
, from:
"IsAllDay"
}
}
}
}
}
});
it goes in and hits read no problem, returning the location ID so that the webapi controller knows what database to connect to
this is important to my set up, as this is a template that many MANY locations are currently using (without our network), so each controller that we ever use has to know what database to pull from, hence always sending locationID in, in addition to the ID of the item I am dealing with (in the case of a delete)
So now that is out of the way, am I still doing something wrong?
So I have been trying all sorts of ideas to get the parameterMap to work.. I have had some limited success
$(
"#calendar"
).kendoScheduler({
batch:
false
,
height: 600,
views: [
"day"
,
"week"
,
{ type:
"month"
, selected:
true
},
"agenda"
],
dataSource: {
transport: {
create: {
dataType:
"jsonp"
},
read: {
url: BaseAPI +
"/NewFullCalendar"
,
dataType:
"json"
},
update: {
dataType:
"jsonp"
},
destroy: {
type:
"delete"
,
url: BaseAPI +
"/Calendar"
,
datatype:
"json"
,
},
parameterMap:
function
(options, operation) {
if
(operation ==
"create"
) { alert(
'ive been created'
);
return
{ location: locationID }; }
if
(operation ==
"read"
) { alert(
'Ive been read'
);
return
{ location: locationID }; }
if
(operation ==
"update"
) { alert(
'ive been updated'
);
return
kendo.stringify({ location: locationID, ID: options.models[0].id }); }
if
(operation ==
"destroy"
) { alert(
'ive been destroyed'
);
return
kendo.stringify({ location: locationID, ID: options.models[0].id }); }
}
},
schema: {
model: {
id:
"id"
,
fields: {
ID: { from:
"ID"
, type:
"number"
},
title: { from:
"title"
, defaultValue:
"No title"
, validation: { required:
true
} },
start: { type:
"date"
, from:
"start"
},
end: { type:
"date"
, from:
"end"
},
description: { from:
"Content"
},
recurrenceId: { from:
"recurrenceID"
},
recurrenceRule: { from:
"recurrenceRule"
},
recurrenceException: { from:
"recurrenceException"
},
isAllDay: { type:
"boolean"
, from:
"IsAllDay"
}
}
}
}
}
});
What I am needing to do is send a global variable in (locationID), which is needed for our controllers (webapi) to know what data base to use/ naturally I would also need to get other information:
destroy needs to know what database to use, AND what eventID to delete.
Create needs to know what database to use, and a host of other data
update needs to know what database to use, what ID we are looking at, and what data to change
read only needs to know what database to use.
I cannot reproduce such problems in this demo: http://jsbin.com/udifit/1/edit
Deleting an event always hits destroy. Perhaps your scheduler event is not properly configured. Check if all the fields are properly mapped to the response returned by your "read " service.
Other than that sending the additional field is done via parameterMap just as you have implemented it.
Atanas Korchev
Telerik
So I dont know if thats what is causing the issue there or not. I assume when you guys test the problems we post, you test the current version thats in production, and me like an idiot forgot I was using an internal build
forgive me?
No, the problem should be caused by the internal build.
I noticed another problem - during "read" you are not calling kendo.stringify. WebAPI however needs its parameters to be sent in JSON format. Perhaps adding that would properly pass the parameters.
The only other thing I can suggest is to attach your actual project so we can run it locally and see what is wrong.
Atanas Korchev
Telerik
I'll see what I can do about getting you guys a copy of the project, although you wouldnt be able to connect to our web service (due to the way our project works, its a content management system for about 80 different schools within our district)
So, running it locally probably wouldnt work:
to get to the page I am working on you have to have an authenticated account within our system, among other problems.
generally (in my experience with this project) webapi doesnt particularly care if I havent stringified the read statement, unless im using more than one parameter. in the case of this read, I am only sending in locationID (and in fact it actually works, I get to see the events I preloaded into the DB manually)
something is telling the scheduler in some way shape or form, that i am creating when I am actually destroying
hopefully this will tell you guys something, otherwise its looking like I just cant use the scheduler within our project, which just sucks.
Yes, I meant "shouldn't". Sorry for the typo.
I created a short sample project which shows how to implement CRUD with WebAPI. It uses in memory data but this should not be related. Please find it attached to this thread.
Atanas Korchev
Telerik
At one point I had it working, but I wasnt using the transport methods, I was however using save remove and edit.
the reason I changed off of using those, was because save gets called from edit and new.. so I would have had to determined in some way if the event was a new event, or if it was something that was being edited from the datasource.. and I still had those wonky r is undefined errors.
We have seperated our web service (api, whatever you call it) into its own entity, so that each site can call back to a single service location, instead of each site having its own service (which is what prevents me from actually debugging this thing properly, unless I have a copy of the service running locally)
I have seen many different ways to format the parameter map, so its difficult to see which is "the right way" for what I am doing.
I'll keep trying.
As we have already attached a working demo, showing a possible implementation of the functionality you are looking for, please check it again and see what differs from the project that you have. I hope you will figure it out.
Regards,
Kiril Nikolov
Telerik
I know this forum topic is super old, but thought I would throw this out there as I had a VERY similar issue and it was driving me crazy. Looks like you have the same code issue as I did in your schema
schema: {
model: {
id:
"id"
,
fields: {
ID: { from:
"ID"
, type:
"number"
},
title: { from:
"title"
, defaultValue:
"No title"
, validation: { required:
true
} },
start: { type:
"date"
, from:
"start"
},
end: { type:
"date"
, from:
"end"
},
description: { from:
"Content"
},
recurrenceId: { from:
"recurrenceID"
},
recurrenceRule: { from:
"recurrenceRule"
},
recurrenceException: { from:
"recurrenceException"
},
isAllDay: { type:
"boolean"
, from:
"IsAllDay"
}
}
}
}
}
notice, how you reference id: as "id"
Well in your fields block it is ID:
Apparently the case matters ALOT check out the updated below, I made it id: ( lower case in the fields block ) that fixed my issue. Hopefully this helps someone in the future
schema: {
model: {
id:
"id"
,
fields: {
id: { from:
"ID"
, type:
"number"
},
title: { from:
"title"
, defaultValue:
"No title"
, validation: { required:
true
} },
start: { type:
"date"
, from:
"start"
},
end: { type:
"date"
, from:
"end"
},
description: { from:
"Content"
},
recurrenceId: { from:
"recurrenceID"
},
recurrenceRule: { from:
"recurrenceRule"
},
recurrenceException: { from:
"recurrenceException"
},
isAllDay: { type:
"boolean"
, from:
"IsAllDay"
}
}
}
}
}