I really don't know How to reset datasouce with Grid. I searched some materials, and some info said use setDataSource() method. It didn't work. I have no idea. please help me.
//I really want to reset datasouce here, thanks
<
button
onclick
=
"LoadPerson1()"
>Load User 1</
button
>
<
button
onclick
=
"LoadPerson2()"
>Load User 2</
button
>
<
div
id
=
"grid"
></
div
>
<
script
>
var personModel
var grid;
$(function () {
personModel = {
user: {
ObjectId: "",
PrincipalName: "",
Userinfos: []
}
};
grid = $("#grid").kendoGrid({
toolbar: [
{ name: "create" },
{ name: "save" },
{ name: "cancel" }
],
columns: [
{ field: "Key" },
{ field: "Value" }
],
dataSource: personModel.user.Userinfos,
editable: true
}).data("kendoGrid");
});
function LoadPerson1() {
$.ajax({
cache: false,
type: "post",
dataType: "json",
url: "Home/GetUser",
success: function (data) {
personModel.user.ObjectId = data.ObjectId;
personModel.user.PrincipalName = data.PrincipalName;
personModel.user.Userinfos = data.Userinfos;
//I really want to reset datasouce here, thanks
grid.dataSource.data(personModel.user.Userinfos);
grid.dataSource.read();
}
});
}
function LoadPerson2() {
$.ajax({
cache: false,
type: "post",
dataType: "json",
url: "Home/GetUser2",
success: function (data) {
personModel.user.ObjectId = data.ObjectId;
personModel.user.PrincipalName = data.PrincipalName;
personModel.user.Userinfos = data.Userinfos;
}
});
}
</
script
>
above sentences are my all code. The pic I attach is data in personModel.user.UserInfos