我有一个包含多个选项卡的应用程序,并且我的KendoUI网格放置在其中代码位于.js文件中的其中一个选项卡中。 (即视图具有div标签,然后将div标签呈现为.js文件中的KendoUI网格)。它的数据源从基于MVC的应用程序的模型文件中写入的类中获取值。我想让网格可编辑,并在移动到任何其他选项卡时异步保存更改到数据源。 在这个方向的任何指针将是巨大的......编辑并保存对kendoUI网格的数据源所做的更改
MVC应用程序的视图文件包含:
<div id="example" class="k-content">
<div id="grid"></div>
div标签呈现给KendoUi电网.js文件。代码如下:
function createGrid()
{
$("#grid").kendoGrid({
dataSource: dataSource,
height: 430,
columns: [
{ field:"ProductName",title:"Product Name" },
{ field: "Category", title: "Category"},
{ field: "UnitPrice", title:"Unit Price" },
editable: true
});
}
function createDataSource()
{
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: BaseUrl + "/Products", //this is the action method in Controller which returns a list of Products which is hardcoded in this method itself.
dataType: "json"
},
autoSync: true,
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true } },
Category: { defaultValue: { CategoryID: 1, CategoryName: "Beverages"} },
UnitPrice: { type: "number", validation: { required: true, min: 1} }
}
}
}
});
}
单击选项卡/按钮时调用createDataSource()和createGrid()函数。 我希望在单击任何其他选项卡时,将此可编辑网格中所做的更改保存到数据源中。
我尝试了使autoSync:true,但值没有被保存。 – sandy 2013-05-01 07:58:43
除非我看到您的代码,否则我无法进一步提供帮助。 – 2013-05-01 08:31:01
我已编辑帖子以包含代码。 – sandy 2013-05-01 18:20:28