Hello,
I'm currently trying to create a variable that will be used as a grid DataSource. When I create a typeless variable, this is working perfectly.... however, if I cast my variable as a kendo.data.DataSource, the grid doesn't work anymore.
Here's my code:
As mentionned in the code, myDataSource is working but not myDataSource2.
Am I missing something here?
Best regards,
Simon
I'm currently trying to create a variable that will be used as a grid DataSource. When I create a typeless variable, this is working perfectly.... however, if I cast my variable as a kendo.data.DataSource, the grid doesn't work anymore.
Here's my code:
var myDataSource = {
schema: {
model: {
id: "RecordID",
fields: {
RecordID: { editable: false, nullable: true },
FirstName: { editable: true },
LastName: { editable: true }
}
}
},
type: "odata",
serverPaging: true,
serverSorting: true,
pageSize: 100,
batch: false,
transport: {
read: "http://localhost:1625/Data/GetPatients",
create: { url: "http://localhost:1625/Data/Create", contentType: "application/json; charset=utf-8", type: "POST" },
update: { url: "http://localhost:1625/Data/Update", contentType: "application/json; charset=utf-8", type: "POST" },
destroy: { url: "http://localhost:1625/Data/Destroy", contentType: "application/json; charset=utf-8", type: "POST", dataType: "json" },
parameterMap: function (data, operation) {
if (operation !== "read") {
return kendo.stringify(data);
} else {
return kendo.data.transports["odata"].parameterMap(data, operation);
}
}
}
};
var myDataSource2 = new kendo.data.DataSource({
schema: {
model: {
id: "RecordID",
fields: {
RecordID: { editable: false, nullable: true },
FirstName: { editable: true },
LastName: { editable: true }
}
}
},
type: "odata",
serverPaging: true,
serverSorting: true,
pageSize: 100,
batch: false,
transport: {
read: "http://localhost:1625/Data/GetPatients",
create: { url: "http://localhost:1625/Data/Create", contentType: "application/json; charset=utf-8", type: "POST" },
update: { url: "http://localhost:1625/Data/Update", contentType: "application/json; charset=utf-8", type: "POST" },
destroy: { url: "http://localhost:1625/Data/Destroy", contentType: "application/json; charset=utf-8", type: "POST", dataType: "json" },
parameterMap: function (data, operation) {
if (operation !== "read") {
return kendo.stringify(data);
} else {
return kendo.data.transports["odata"].parameterMap(data, operation);
}
}
}
});
$(document).ready(function () {
$("#grid").kendoGrid({
dataSource: myDataSource, //This is working but if you change it to myDataSource2, then it doesn't work
height: 500,
scrollable: {
virtual: true
},
editable: true,
sortable: true,
toolbar: ["create", "save"],
columns: ["RecordID", "FirstName", "LastName", { command: "destroy"}]
});
});
As mentionned in the code, myDataSource is working but not myDataSource2.
Am I missing something here?
Best regards,
Simon