单击按钮,清除jqgrid并重新加载数据

sah*_*ana 4 jquery jqgrid

我有一个不在document.ready内的jqgrid.只有当我点击一个按钮时才会触发它.

  function getData{
    DataHandler.getTasks(locName,{callback:function(data){
    jQuery("#TaskTable").jqGrid(
                {
    datatype : "local",
    data : resultSet,
    height : 250,
    width : 960,
    sortable : false,
    ignoreCase : true,
    sortorder : "desc",
        //rest of the table contents like colname and colmodel
     });

    }, errorHandler:function(){

        },async:false

    });
Run Code Online (Sandbox Code Playgroud)

我想清除每个按钮上的网格,以便删除已存在的数据并重新加载.这样做有什么帮助吗?我应该在文档准备就绪或点击按钮时将清晰的网格放在哪里?

谢谢

Kev*_*ine 7

假设标记为:

 <table id='myGrid' />
Run Code Online (Sandbox Code Playgroud)

您可以使用以下代码从服务器清除并加载新数据:

function loadTable() {
$('#myGrid').jqGrid('GridUnload');  //this does the work of clearing out the table content and loading fresh data
$('myGrid').jqGrid({
    url: 'url goes here',
    dataType: 'json',
    jsonReader: {
        root: 'Data',
        page: 'CurrentPage',
        total: 'TotalPage',
        records: 'TotalRecords',
        repeatitems: false
    },
    onSelectRow: editRow
});
Run Code Online (Sandbox Code Playgroud)

}

您还可以查看以下链接以获取更多信息.