Dee*_*ali 2 kendo-ui kendo-grid kendo-asp.net-mvc
如何在ajax帖子成功后刷新kendo ui网格?这是我的网格ajax帖子:
var newUser = {
UserId: 0,
UserLoginName: currentRecord.UserLoginName,
UserDisplayName: currentRecord.UserDisplayName
};
//insert selected rows using DataSource insert method
destinationGrid.dataSource.insert(newRecord);
//ajax post to server
var url = '@Url.Action("CreateUser", "ManageUsers")';
$.post(url, { loginid: currentRecord.UserLoginName, name: currentRecord.UserDisplayName, role: roleSelected }, function (result) {
if (result.Success) {
**////grid is not refreshing as I want to refersh the grid again from database**
destinationGrid.dataSource.read();
}
});
}
Run Code Online (Sandbox Code Playgroud)
Jai*_*min 10
这只是一个例子
$.ajax({
url: '@Url.Action("NewGridView", "Test")',
type: "Post",
data: { sampleItem: sampleItem, sampleCode: sampleCode, sampledescription: sampledescription },
dataType: 'json',
success: function (result) {
$('#gridName').data("kendoGrid").dataSource = new kendo.data.DataSource({ data: result });
$('#gridName').data("kendoGrid").dataSource.read();
$('#gridName').data("kendoGrid").refresh();
}
});
Run Code Online (Sandbox Code Playgroud)
调节器
public JsonResult NewGridView(string sampleItem, string sampleCode, string sampledescription)
{
List<SampleModel> sampleAddList = new List<SampleModel>();
SampleModel sampleAdd = new SampleModel();
sampleAdd.SampleCode = sampleCode;
sampleAdd.SampleDescription = sampledescription;
sampleAdd.SampleItems = sampleItem;
sampleAddList.Add(sampleAdd);
var result = sampleAddList;
return Json(result, JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud)
如果您需要在complate控制器操作完成后立即刷新网格,
$('#gridName').data("kendoGrid").dataSource = new kendo.data.DataSource({ data: result }); 在你的 post success
据我了解,您需要在成功更新后刷新您的剑道网格(相当于 $.ajaxsuccess:回调),对吧?
在这种情况下,kendo grid 没有任何成功回调,而是使用回调complete。在运输中尝试以下操作;
dataSource: {
transport: {
read: {
url: "/YourController/LoadYourGridData",
type: "POST",
contentType: "application/json",
dataType: "json"
},
update: {
url: "/YourController/UpdateYourGridData",
contentType: "application/json; charset=utf-8",
type: "POST",
dataType: "json",
complete: function (data) {
$("#Grid").data("kendoGrid").dataSource.read();
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11995 次 |
| 最近记录: |