如何在 ajax post 回调后刷新 KendoUi 网格 [英] How to refresh the KendoUi grid after a ajax post callback
本文介绍了如何在 ajax post 回调后刷新 KendoUi 网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ajax发帖成功后如何刷新剑道ui网格?这是我的网格 ajax 帖子:
How to refresh the kendo ui grid after a ajax post is successful? Here is my grid ajax post:
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();
}
});
}
推荐答案
这只是例子
$.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();
}
});
控制器
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);
}
如果您需要在完成控制器操作后立即刷新网格,
if you need to refresh your grid as soon as complate controller action do this,
$('#gridName').data("kendoGrid").dataSource = new kendo.data.DataSource({ data: result });
在你的 post 成功
代码>
这篇关于如何在 ajax post 回调后刷新 KendoUi 网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文