刷新或重新加载数据表

use*_*864 7 datatable jquery

我正在使用Jquery Datatable,其中包括列的自定义渲染.基于值,我将禁用其中的某些控件.我希望在发布后重新加载/刷新/重新绑定我的jquery数据表.我怎样才能做到这一点?

**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>
Run Code Online (Sandbox Code Playgroud)

更新:**

我找到了答案:

  • 清除表格(fnClearTable)

  • 向表中添加新数据(fnAddData)

  • 重绘表格(fnDraw)

Pra*_*eek 19

首先得到数据表参考,使用

var oTable = $("#someTable").dataTable();
Run Code Online (Sandbox Code Playgroud)

在那之后做任何事情,你想:

Clear the table : oTable.fnClearTable();

Redraw the table : oTable.fnDraw();

Add new data to the table : oTable.fnAddData();
Run Code Online (Sandbox Code Playgroud)


use*_*864 2

我找到了答案:

clear the table ( fnClearTable )

add new data to the table ( fnAddData)

redraw the table ( fnDraw )
Run Code Online (Sandbox Code Playgroud)