Kendo UI Scheduler Datasource - javascript

I am trying to implement Kendo UI scheduler. But I can't seem to get the datasource to work.
My JS is:
var diary = {
open: function() {
dialog('diary', function() {
$('#diaryDialog').css('width', '1450px');
$('#calendar').kendoScheduler({
date: new Date("2013/6/13"),
startTime: new Date("2013/6/13 07:00 AM"),
height: 700,
views: [
"day",
{type: "workWeek", selected: true},
"week",
"month",
"agenda"
],
timezone: "Etc/UTC",
dataSource: {
batch: true,
transport: {
read: {
url: ROOT + "Diary/fetchDiary",
type: "POST",
dataType: "json"
},
update: {
url: "http://demos.telerik.com/kendo-ui/service/tasks/update",
dataType: "json"
},
create: {
url: "http://demos.telerik.com/kendo-ui/service/tasks/create",
dataType: "json"
},
destroy: {
url: "http://demos.telerik.com/kendo-ui/service/tasks/destroy",
dataType: "json"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return kendo.stringify(options.models);
}
}
},
schema: {
model: {
id: "taskId",
fields: {
taskId: {from: "TaskID", type: "number"},
title: {from: "Title", defaultValue: "No title", validation: {required: true}},
start: {type: "date", from: "Start"},
end: {type: "date", from: "End"},
startTimezone: {from: "StartTimezone"},
endTimezone: {from: "EndTimezone"},
description: {from: "Description"},
recurrenceId: {from: "RecurrenceID"},
recurrenceRule: {from: "RecurrenceRule"},
recurrenceException: {from: "RecurrenceException"},
ownerId: {from: "OwnerID", defaultValue: 1},
isAllDay: {type: "boolean", from: "IsAllDay"}
}
}
},
filter: {
logic: "or",
filters: [
{field: "ownerId", operator: "eq", value: 1},
{field: "ownerId", operator: "eq", value: 2}
]
}
},
})
})
}
}
And the when it initialises the data string that comes over is:
[{"TaskID":4,
"OwnerID":2,
"Title":"Bowling tournament",
"Description":"",
"StartTimezone":null,
"Start":"Date(1370811600000)",
"End":"Date(1370822400000)",
"EndTimezone":null,
"RecurrenceRule":null,
"RecurrenceID":null,
"RecurrenceException":null,
"IsAllDay":false}]
But it isn't working and I am getting an error in console:
Uncaught TypeError: Cannot read property 'getTimezoneOffset' of null
My PHP:
public function fetchDiary() {
echo '[{
"TaskID":4,
"OwnerID":2,
"Title":"Bowling tournament",
"Description":"",
"StartTimezone":null,
"Start":"Date(1370811600000)",
"End":"Date(1370822400000)",
"EndTimezone":null,
"RecurrenceRule":null,
"RecurrenceID":null,
"RecurrenceException":null,
"IsAllDay":false}]';
}

Related

Telerik scheduler - tasks disappear when culture is changed

I use telerik scheduler in html+js. My code is:
$(document).ready(function () {
kendo.culture("pl-PL");
$("#scheduler").kendoScheduler({
date: new Date("2016/3/4"),
startTime: new Date("2016/3/4 07:00"),
views: [
"day",
{ type: "workWeek", selected: true },
"week",
"month"
],
timezone: "Europe/Warsaw",
dataSource: {
batch: true,
transport: {
read: {
url: "../Meetings/Read",
dataType: "jsonp"
},
update: {
url: "http://demos.telerik.com/kendo-ui/service/tasks/update",
dataType: "jsonp"
},
create: {
url: "http://demos.telerik.com/kendo-ui/service/tasks/create",
dataType: "jsonp"
},
destroy: {
url: "http://demos.telerik.com/kendo-ui/service/tasks/destroy",
dataType: "jsonp"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
schema: {
model: {
id: "ID",
fields: {
ID: { from: "MeetingID" ,type: "number" },
title: { from: "Title", defaultValue: "No title", validation: { required: true } },
start: { type: "date", from: "Start" },
end: { type: "date", from: "End" },
description: { from: "Description" },
recurrenceId: { from: "RecurrenceID" },
recurrenceRule: { from: "RecurrenceRule" },
recurrenceException: { from: "RecurrenceException" },
ownerId: { from: "OwnerID", defaultValue: 1 },
isAllDay: { type: "boolean", from: "IsAllDay" }
}
}
},
filter: {
logic: "or",
filters: [
{ field: "ownerId", operator: "eq", value: 1 },
{ field: "ownerId", operator: "eq", value: 2 }
]
}
},
resources: [
{
field: "ownerId",
title: "Owner",
dataSource: [
{ text: "Alex", value: 1, color: "#f8a398" },
{ text: "Bob", value: 2, color: "#51a0ed" },
{ text: "Charlie", value: 3, color: "#56ca85" }
]
}
]
});
});
Like you see I've changed culture of scheluder (date and time format, names of days, months etc.) and timezone. All of my tasks are disappear. If I removed first line (kendo.culture("pl-PL")) tasks will be shown.
How can I work with changing culture and timezone in the same time? It's even posiible?
Edit
My sample value returned by controller is:
{"MeetingID":1,"Start":"2016-03-01T08:30:00","End":"2016-03-01T07:30:00","Title":"Testowe","Description"
:"ASD","OwnerID":1,"IsAllDay":false,"RecurrenceRule":"","RecurrenceID":1,"RecurrenceException":"","StartTimezone"
:"","EndTimezone":""}
Have you Included the file kendo.timezones.min.js ?
If not then you have to add (in your header html section)the following line
<script src="http://kendo.cdn.telerik.com/2016.1.112/js/kendo.timezones.min.js"></script>
You can find a working sample here http://dojo.telerik.com/udAyo

How to add radio buttons which have multiple choice

I want to use use a popup menu for registration and I have to use radio button on it somewhere. It should have multiple choices and just one is able to chosen.
Here is my code:
Here is my PersonModel.js
define([
'kendo/kendo.data.min', 'robe/Validations'], function () {
var PersonModel = kendo.data.Model.define({
id: "oid",
fields: {
oid: {
editable: false,
nullable: true,
type: "string"
},
lastUpdated: {
editable: true,
nullable: true,
type: "string"
},
tckNo:{
editable:true,
nullable:false,
type:"string",
validation :getValidations("tckNo","T.C. Kimlik Numarası",true,false,11,11,"[0-9]")
},
name: {
editable: true,
nullable: false,
type: "string"
},
surname: {
editable: true,
nullable: false,
type: "string"
},
birthday: {
editable: true,
nullable: false,
type: "date"
},
isSingle:{
editable:true,
nullable:false,
type:"boolean"
}
}
});
return PersonModel;});
Here is PersonDataSource.js
define(['common/SingletonDataSource', './PersonModel'], function (SingletonDataSource, personModel) {
var personDataSource = SingletonDataSource.define({
name: "personDataSource",
parameters: {
transport: {
read: {
type: "GET",
url: AdminApp.getBackendURL() + "person/all",
dataType: "json",
contentType: "application/json"
},
update: {
type: "POST",
url: AdminApp.getBackendURL() + "person",
dataType: "json",
contentType: "application/json"
},
destroy: {
type: "DELETE",
url: AdminApp.getBackendURL() + "person",
dataType: "json",
contentType: "application/json"
},
create: {
type: "PUT",
url: AdminApp.getBackendURL() + "person",
dataType: "json",
contentType: "application/json"
},
parameterMap: function (options, operation) {
if (operation !== "read") {
return kendo.stringify(options);
}
}
},
batch: false,
pageSize: 25,
schema: {
model: personModel
}
}
});
return personDataSource;});
And here is PersonManagement.js :
define([
'text!./PersonManagement.html',
'./PersonDataSource',
'kendo/kendo.grid.min',
'robe/view/RobeView'],
function(view,PersonDataSource){
var PersonManagementView = require('robe/view/RobeView').define({
name:"PersonManagementView",
html:view,
containerId:"container",
initialize:function(){
var grid = $("#personGrid").kendoGrid({
dataSource: PersonDataSource.get(),
sortable: true,
autoBind: false,
pageable: {
refresh: true
},
toolbar: [
{
name: "create",
text: "Yeni Kişi"
}
],
columns: [
{
field:"tckNo",
title:"TC Kimlik Numarası",
format:"{0:n0}"
},
{
field: "name",
title: "Ad"
},
{
field: "surname",
title: "Soyad"
},
{
field: "birthday",
title: "Doğum Günü"
},
{
command: [
{
name: "edit",
text: {
edit: "",
update: "Tamam",
cancel: "İptal"
},
className: "grid-command-iconfix"
},
{
name: "destroy",
text: "",
className: "grid-command-iconfix"
}
],
title: " ",
width: "120px"
}
],
editable: {
mode: "popup",
window: {
title: "Kayıt".i18n()
},
confirmation: "Silmek istediğinizden emin misiniz?".i18n(),
confirmDelete: "Yes"
}
});
}
});
return PersonManagementView;
}
);
Can you help me please?
You have too use checkboxes.
Radio-Buttons don't allow multiple selection.

Kendo ui Grid shows [object object]

I have a Kendo UI grid, that will only display values like [object object] even if the type is "string". I have the datasource for the grid working with a graph, so I know there is data, and that it should be showing other values.
I'm using MVVM
Datasource:
var dataSource = new kendo.data.DataSource({
type: "everlive",
autoSync: true,
serverFiltering: true,
filter: {
field: "DeviceID",
operator: "eq",
value: device.uuid
},
transport: {
// binding to the Order type in Everlive
typeName: "BreakPoint"
},
schema: {
model: {
id: "Id",
fields: {
// default Everlive fields
CreatedBy: {
type: "string"
},
CreatedAt: {
type: "date"
},
ModifiedAt: {
type: "date"
},
// type fields
Energi: {
type: "number"
},
Note: {
type: "string"
},
activity_green: {
type: "bool"
},
activity_yellow: {
type: "bool"
},
activity_red: {
type: "bool"
}
}
}
}
});
HTML:
<div data-role="grid"
data-theme="silver"
date-scrollable="true"
data-pageable="true"
data-columns="[
{ 'field': 'CreatedAt', template:'#= formatAddress(data) #'},
{ 'field': 'Note' },
{ field: 'Energi', format:'{0:c}'},
{ field: 'activity_green', title: 'Grøn Aktivitet', format:'{0:c}'},
{ field: 'activity_yellow', title: 'Gul Aktivitet', format:'{0:c}'},
{ field: 'activity_red', title: 'Rød Aktivitet', format:'{0:c}'}
]"
data-bind="source: ds"
style="height: 200px"></div>

Extjs 5, data model association & load nested data

trying to make this work....
I want to load nested data on two object model
Ext.application({
name : 'MyApp',
launch : function() {
Ext.define('MyApp.model.Address', {
extend: 'Ext.data.Model',
entityName: 'Address',
fields: [
{
name: 'id',
type: 'int'
},
{
name: 'addressLine',
type: 'string'
},
{
name: 'city',
type: 'string'
},
{
name: 'created',
type: 'date',
dateFormat: 'time',
persist: false
}
]
});
Ext.define('MyApp.model.User', {
extend: 'Ext.data.Model',
entityName: 'User',
fields: [
{
name: 'id',
type: 'int'
},
{
name: 'address',
reference: 'Address'
},
{
name: 'name',
type: 'string'
},
{
name: 'lastname',
type: 'string'
},
{
name: 'created',
type: 'date',
dateFormat: 'time',
persist: false
}
]
});
var user = new MyApp.model.User({
"id": 1,
"name": "Pedro",
"lastname": "Carbonell",
"address": {
"id": 1,
"addressLine": "Bailen 22",
"city": "Barcelona",
"created": 1420668866000
},
"created": 1420668866000
});
console.info(user);
console.info(user.getAddress());
}});
It's result on no error when created the user, but when I access to associated data via user.getAddress() it returned an exception:
Uncaught Error: The model ID configured in data ("[object Object]") has been rejected by the int field converter for the id fieldext-all-debug.js
Try to define proxy like memory or localstorage on model definitions, but the result it is the same.
Ext fiddle: https://fiddle.sencha.com/#fiddle/h2d
Any help will be appreciated!
Solved, but only find this solution: when use loadRawData...
var store = new Ext.data.Store({
model: MyApp.model.User
});
store.loadRawData({
"id": 1,
"name": "Pedro",
"lastname": "Carbonell",
"address": {
"id": 1,
"addressLine": "Bailen 22",
"city": "Barcelona",
"created": 1420668866000
},
"created": 1420668866000
});
console.info(store.first());
console.info(store.first().getAddress());
sample at this new fiddle: https://fiddle.sencha.com/#fiddle/h4e
you'r right, ext is a bit flaky, very....
I've been playing around with the code in your fiddle and not been able to get the association working the official way as of yet.
I simulated the functionality using this code:
Ext.define('MyApp.model.User', {
extend: 'Ext.data.Model',
fields: [{
name: 'id',
type: 'int'
}, {
name: 'name',
type: 'string'
}, {
name: 'lastname',
type: 'string'
}, {
name: 'created',
type: 'date',
dateFormat: 'time',
persist: false
}],
getAddress: function() {
if ('undefined' === this.data.address) {
return null;
}
return Ext.create('Address', this.data.address);
}
});
Basically I've removed the association and created a custom function to create a model record based off of the raw data passed in, You could also return a new, empty model if the address data does not exist instead of null, I used null as it's easier to determine whether you have a valid address record or not.
As already mentioned - this is not the official way to do this, I will have another play around with the fiddle and post a better solution once I find it, this may help in the meantime.
Using the original code, I made a few modifications and now it appears to be working.
Ext.application({
name : 'MyApp',
launch : function() {
Ext.define('MyApp.model.Address', {
extend: 'Ext.data.Model',
//entityName: 'Address',
fields: [
{
name: 'id',
type: 'int'
},
{
name: 'addressLine',
type: 'string'
},
{
name: 'city',
type: 'string'
},
{
name: 'created',
type: 'date',
dateFormat: 'time',
persist: false
}
],
hasMany: 'User'
});
Ext.define('MyApp.model.User', {
extend: 'Ext.data.Model',
//entityName: 'User',
fields: [
{
name: 'id',
type: 'int'
},
{
name: 'name',
type: 'string'
},
{
name: 'lastname',
type: 'string'
},
{
name: 'created',
type: 'date',
dateFormat: 'time',
persist: false
}
],
hasMany: { model: 'Address', name: 'Address' }
});
var user = new MyApp.model.User({
"id": 1,
"name": "Pedro",
"lastname": "Carbonell",
"address": {
"id": 1,
"addressLine": "Bailen 22",
"city": "Barcelona",
"created": 1420668866000
},
"created": 1420668866000
});
console.info(user);
console.info(user.data.address);
}
});
Is this the sort of thing you're after? I set Address manually on the User model. Not ideal but it's interpreted correctly as a record then.
Ext.define('MyApp.model.Address', {
extend: 'Ext.data.Model',
entityName: 'Address',
fields: [
{
name: 'id',
type: 'int'
},
{
name: 'addressLine',
type: 'string'
},
{
name: 'city',
type: 'string'
},
{
name: 'created',
type: 'date',
dateFormat: 'time',
persist: false
}
]
});
Ext.define('MyApp.model.User', {
extend: 'Ext.data.Model',
entityName: 'User',
fields: [
{
name: 'id',
type: 'int'
},
{
name: 'addressId',
reference: 'Address'
},
{
name: 'name',
type: 'string'
},
{
name: 'lastname',
type: 'string'
},
{
name: 'created',
type: 'date',
dateFormat: 'time',
persist: false
}
]
});
var user = new MyApp.model.User({
"id": 1,
"name": "Pedro",
"lastname": "Carbonell",
"created": 1420668866000
});
var addr = new MyApp.model.Address({
"id": 1,
"addressLine": "Bailen 22",
"city": "Barcelona",
"created": 1420668866000
});
user.setAddress(addr);
console.info(user);
console.info(user.getAddress());

Kendo UI Scheduler not binding resources properly

I'm having trouble trying to get my KendoUI Scheduler resources to populate correctly. I haven't found a good example of how to bind a nested JSON object (in this case Task and User listed in the screenshot) to resources that are fetched.
Also while running Fiddler, it seems like the resources listed below aren't even fetched from the web service. The documentation is super unclear on some of the specifics and I'm having a hard time finding the problem.
The schedule actually pulls back all the SchedulerEvents (the JSON fetched below) and shows me events bound to the Schedule properly, just they have no resources attached. Right now all of my webservice calls are running off localhost so JSONP shouldn't be required yet as my service calls are all calling "localhost".
I did find something similar to what I'm trying to do with projection of data here via Telerik's documentation, but I haven't been able to figure out a good solution yet.
Edited : updated my question with individual DataSource code
Edited 2 : I should also mention since posting this, the JSON screenshot isn't entirely accurate anymore as I've taken ScheduledTaskId and UserId (the two identifying properties of my Task and User resources I'm trying to add to appointments) and made that property available directly from my SchedulerEvent class to avoid nesting objects.
Javascript
//Datasources code has been moved to here. Explicitly fetching data and assigning to Resources datasource properties
$("#scheduler").kendoScheduler({
date: new Date("#DateTime.Now.ToShortDateString()"),
timezone: "Etc/UTC",
views: [
"day",
{ type: "week", selected: true },
"month",
"agenda"
],
dataSource: {
batch: true,
transport: {
read: {
url: "ServiceURI/Schedule/Get",
dataType: "json"
},
update: {
url: "",
dataType: "json"
},
create: {
url: "",
dataType: "json"
},
destroy: {
url: "",
dataType: "json"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
resources: [
{
field: "userId",
title: "User",
dataTextField: "displayName",
dataValueField: "userId",
dataSource: userDataSource
}
{
field: "scheduledTaskId",
title: "Task",
dataTextField: "taskName",
dataValueField: "scheduledTaskId",
dataSource: taskDataSource
}
],
schema: {
model: {
id: "shiftId",
fields: {
shiftId: {
from: "ShiftId",
type: "number"
},
title: {
from: "Title",
validation: { required: true }
},
start: {
from: "Start",
type: "date",
validation: { required: true }
},
end: {
from: "End",
type: "date",
validation: { required: true }
},
scheduledTaskId: {
from: "ScheduledTaskId",
type: "number"
},
userId: {
from: "UserId",
type: "number"
},
description: {
from: "Description"
},
recurrenceId: { from: "RecurrenceID" },
recurrenceRule: { from: "RecurrenceRule" },
recurrenceException: { from: "RecurrenceException" },
isAllDay: { type: "boolean", from: "IsAllDay" }
}
}
}
}
});
Datasources
var userDataSource = new kendo.data.DataSource({
transport: {
read: {
//This should be a customized list of users, or all users fetched from the datastore
url: "ServiceURI/UserProfile/Get/",
dataType: "json"
},
},
schema: {
model: {
id: "userId",
fields: {
userId: {
from: "UserId",
type: "number"
},
displayName: {
from: "DisplayName"
}
}
}
}
});
userDataSource.fetch();
var taskDataSource = new kendo.data.DataSource({
transport: {
read: {
//This should be the entire list of tasks fetched from the datastore
url: "ServiceURI/ScheduledTask/Get?companyId=1",
dataType: "json"
}
},
schema: {
model: {
id: "scheduledTaskId",
fields: {
scheduledTaskId: {
from: "ScheduledTaskId",
type: "number"
},
taskName: {
from: "TaskName"
}
}
}
}
});
taskDataSource.fetch();
JSON returned
Problem
The resources object is inside of the dataSource object as I thought it was supposed to be per the documentation
views: [
"day",
{ type: "week", selected: true },
"month",
"agenda"
],
dataSource: {
resources: [
{
field: "userId",
title: "User",
dataTextField: "displayName",
dataValueField: "userId",
dataSource: userDataSource
}
{
field: "scheduledTaskId",
title: "Task",
dataTextField: "taskName",
dataValueField: "scheduledTaskId",
dataSource: taskDataSource
}
]
}
Answer
Just need to move the resources array outside of the DataSource... works as expected without any explicit .fetch() statements either
views: [
"day",
{ type: "week", selected: true },
"month",
"agenda"
],
resources: [
{
field: "userId",
title: "User",
dataTextField: "displayName",
dataValueField: "userId",
dataSource: userDataSource
}
{
field: "scheduledTaskId",
title: "Task",
dataTextField: "taskName",
dataValueField: "scheduledTaskId",
dataSource: taskDataSource
}
],
dataSource: {
}
DataSource + Scheduler Creation
var userDataSource = new kendo.data.DataSource({
transport: {
read: {
//This should be a customized list of users, or all users fetched from the datastore
url: "ServiceURI/UserProfile/Get/",
dataType: "json"
},
},
requestEnd: function(e) {
//Start Fetching Task Data Source
taskDataSource.fetch();
},
schema: {
model: {
id: "userId",
fields: {
userId: {
from: "UserId",
type: "number"
},
displayName: {
from: "DisplayName"
}
}
}
}
});
Task DataSource declaration.
var taskDataSource = new kendo.data.DataSource({
transport: {
read: {
//This should be the entire list of tasks fetched from the datastore
url: "ServiceURI/ScheduledTask/Get?companyId=1",
dataType: "json"
}
},
requestEnd: function(e) {
//Once Task and User DataSource have been fetched, create the Scheduler
createScheduler(e);
},
schema: {
model: {
id: "scheduledTaskId",
fields: {
scheduledTaskId: {
from: "ScheduledTaskId",
type: "number"
},
taskName: {
from: "TaskName"
}
}
}
}
});
function createScheduler(e){
$("#scheduler").kendoScheduler({
date: new Date("#DateTime.Now.ToShortDateString()"),
timezone: "Etc/UTC",
views: [
"day",
{ type: "week", selected: true },
"month",
"agenda"
],
dataSource: {
batch: true,
transport: {
read: {
url: "ServiceURI/Schedule/Get",
dataType: "json"
},
update: {
url: "",
dataType: "json"
},
create: {
url: "",
dataType: "json"
},
destroy: {
url: "",
dataType: "json"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
resources: [
{
field: "userId",
title: "User",
dataTextField: "DisplayName",
dataValueField: "UserId",
dataSource: userDataSource
}
{
field: "scheduledTaskId",
title: "Task",
dataTextField: "TaskName",
dataValueField: "ScheduledTaskId",
dataSource: taskDataSource
}
],
schema: {
model: {
id: "shiftId",
fields: {
shiftId: {
from: "ShiftId",
type: "number"
},
title: {
from: "Title",
validation: { required: true }
},
start: {
from: "Start",
type: "date",
validation: { required: true }
},
end: {
from: "End",
type: "date",
validation: { required: true }
},
scheduledTaskId: {
from: "ScheduledTaskId",
type: "number"
},
userId: {
from: "UserId",
type: "number"
},
description: {
from: "Description"
},
recurrenceId: { from: "RecurrenceID" },
recurrenceRule: { from: "RecurrenceRule" },
recurrenceException: { from: "RecurrenceException" },
isAllDay: { type: "boolean", from: "IsAllDay" }
}
}
}
}
});
}
Start the DataSources fetching from User Source then Task Source and finally creation of the Scheduler.
userDataSource.fetch();
I have never tried this before, but I think above would work as per your requirement.
I think your issue is binding Case. In your Datasources for the resource Objects, you have a model definition, taking items from your JSON data and transforming it into a Model:
var userDataSource = new kendo.data.DataSource({
transport: {
read: {
//This should be a customized list of users, or all users fetched from the datastore
url: "ServiceURI/UserProfile/Get/",
dataType: "json"
},
},
schema: {
model: {
id: "userId",
fields: {
userId: {
from: "UserId",
type: "number"
},
displayName: {
from: "DisplayName"
}
}
}
}
});
In your scheduler Binding, you are setting the dataTextField and dataValueField to:
{
field: "userId",
title: "User",
dataTextField: "DisplayName",
dataValueField: "UserId",
dataSource: userDataSource
}
Notice that your model is displayName and userId, but your resource Bindings are DisplayName and UserId - By the time you are binding into the Scheduler resource collection, the data has been transformed into your model schema, and casing is important.
If you correct the casing, that should solve your issue. You will also need to ensure that both Datasources are populated prior to creating the Scheduler object.

Categories

Resources