本文介绍了刷新或重新加载datatable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Jquery Datatable,其中包括列的自定义渲染。基于值,我必须禁用某些控件。我想重新加载/刷新/重新绑定我的jquery datatable后发布。如何做到这一点? **控制器:**
[HttpPost]
public JsonResult PostAction(MyMOdel model)
{
//保存更改为DB
return Json(new
{
Success = result,
}) ;
}
public ActionResult MyAction()
//从DB获取记录并返回JSON
}
**查看:**
@using(Ajax.BeginForm(PostAction,ControllerName,null,
new AjaxOptions
{
UpdateTargetId =update-message,
InsertionMode = InsertionMode.Replace,
HttpMethod =POST,
OnSuccess =updateSuccess
},新{@id =myForm
}
))
{
< table id =myTblclass =display>< tr>< td> col1< / td>< / tr> /表>
}
< script type =text / javascript>
var oTable = $('#myTbl')。dataTable({
sAjaxSource:/ ControllerName / MyAction,
<! - 更多配置 - >
function updateSuccess(data,status,xhr){
// refresh datatable;
}
< / script>
更新: * *
我找到答案:
-
清除表(fnClearTable)
-
将新数据添加到表(fnAddData)
-
重绘表(fnDraw)
解决方案
Ifound the answer:
清除表(fnClearTable)
将新数据添加到表(fnAddData)
重绘表(fnDraw)
I'm using Jquery Datatable which includes customized rendering for columns. Based on values, I've to disable certain control in it. I want to reload/refresh/rebind my jquery datatable after post. How can I do that?
**Controller:**
[HttpPost]
public JsonResult PostAction(MyMOdel model)
{
//save changes to DB
return Json(new
{
Success = result,
});
}
public ActionResult MyAction()
//grab records from DB and return JSON
}
**View:**
@using (Ajax.BeginForm("PostAction", "ControllerName", null,
new AjaxOptions
{
UpdateTargetId = "update-message",
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
OnSuccess = "updateSuccess"
}, new { @id = "myForm"
}
))
{
<table id="myTbl" class="display"><tr><td>col1</td></tr></table>
}
<script type="text/javascript">
var oTable = $('#myTbl').dataTable({
"sAjaxSource": "/ControllerName/MyAction",
<!-- more config -->
function updateSuccess(data, status, xhr) {
//refresh datatable;
}
</script>
Update:**
I found the answer:
clear the table ( fnClearTable )
add new data to the table ( fnAddData)
redraw the table ( fnDraw )
解决方案
Ifound the answer:
clear the table ( fnClearTable )
add new data to the table ( fnAddData)
redraw the table ( fnDraw )
这篇关于刷新或重新加载datatable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!