Every sample I can find works on the premise of multiple rows of data coming back.
In our case there is only one row being returned because this is a single item edit screen.
I have a Web API request that returns an object. Here's the response from the call:
{
"FirstName": "James",
"LastOrCompanyName": "Hancock",
"MiddleName": "Robert",
"Salutation": "Mr.",
"Suffix": null,
"Individual": true,
<...more fields...>
}
It's formatted exactly like that with Json.
What I'm attempting to do is put text boxes that allow edit of those values.
Here's what I have:
var Contact = kendo.data.Model.define({
ID: "ID"
});
dataSource = new kendo.data.DataSource({
type: "json", // specifies data protocol
transport: {
read: { url: "/api/v1/contacts/GetContactByID?id=" + ContactID },
},
schema: {
model: {
id: "ID"
}
},
change: function (e) {
selectedContact = e;
},
error: function (e) {
debugger;
}
});
var viewModel = kendo.observable({
dataSource: dataSource,
hasChanges: false,
change: function () {
this.set("hasChanges", true);
}
});
kendo.bind($("#contact-info"), viewModel);
for sake of argument I also bound a grid to the datasource like so:
$("#g-contact-info").kendoGrid({
groupable: true,
scrollable: { virtual: true },
sortable: true,
pageable: true,
dataSource: dataSource
});
The grid doesn't display any data even though one item came back.
And I can't figure out any way to logically set the observable to the first item even if it did. I was expecting some sort of data control on the observable that allowed you to change which is the current item just like a BindingSource in Winforms or something.
Can someone help with the two issues? First being the data not coming back and binding properly, the second being how do I get the observable to set properly and get my selectedContact set with the right value.
Thanks!
In our case there is only one row being returned because this is a single item edit screen.
I have a Web API request that returns an object. Here's the response from the call:
{
"FirstName": "James",
"LastOrCompanyName": "Hancock",
"MiddleName": "Robert",
"Salutation": "Mr.",
"Suffix": null,
"Individual": true,
<...more fields...>
}
It's formatted exactly like that with Json.
What I'm attempting to do is put text boxes that allow edit of those values.
Here's what I have:
var Contact = kendo.data.Model.define({
ID: "ID"
});
dataSource = new kendo.data.DataSource({
type: "json", // specifies data protocol
transport: {
read: { url: "/api/v1/contacts/GetContactByID?id=" + ContactID },
},
schema: {
model: {
id: "ID"
}
},
change: function (e) {
selectedContact = e;
},
error: function (e) {
debugger;
}
});
var viewModel = kendo.observable({
dataSource: dataSource,
hasChanges: false,
change: function () {
this.set("hasChanges", true);
}
});
kendo.bind($("#contact-info"), viewModel);
for sake of argument I also bound a grid to the datasource like so:
$("#g-contact-info").kendoGrid({
groupable: true,
scrollable: { virtual: true },
sortable: true,
pageable: true,
dataSource: dataSource
});
The grid doesn't display any data even though one item came back.
And I can't figure out any way to logically set the observable to the first item even if it did. I was expecting some sort of data control on the observable that allowed you to change which is the current item just like a BindingSource in Winforms or something.
Can someone help with the two issues? First being the data not coming back and binding properly, the second being how do I get the observable to set properly and get my selectedContact set with the right value.
Thanks!