jQuery 如何让jqGrid重新加载到服务器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3772334/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:04:08  来源:igfitidea点击:

How to get jqGrid reload to go to server?

jqueryjqgridnavigator

提问by Marcus Leon

We use the jqGrid navigator reload button on a grid with loadonceset to true.

我们在loadonce设置为 true的网格上使用 jqGrid 导航器重新加载按钮。

The reload button currently does NOT go back to the server to get the data - how can we get the reload to go to the server to get the latest data?

重新加载按钮当前不会返回服务器获取数据 - 我们如何才能重新加载到服务器以获取最新数据?

I believe we can use the beforeRefreshcallback to set the grid datato jsoninstead of localbut I'm not clear how to even configure the beforeRefreshmethod - I don't really understand the docs.

我相信我们可以使用beforeRefresh回调将网格设置datajson而不是,local但我什至不清楚如何配置该beforeRefresh方法 - 我不太了解文档。

回答by Oleg

You are not the only person which has the problem. I answerd to the same questionbefore. To reload the grid content from the server you should reset the datatypeparameter to original value "json" or "xml" and then refresh the grid. For example

你不是唯一有问题的人。我之前回答同样的问题。要从服务器重新加载网格内容,您应该将datatype参数重置为原始值“json”或“xml”,然后刷新网格。例如

jQuery("#list").jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid');

UPDATED: To call the line inside of beforeRefreshevent handler you can do following

更新:要调用beforeRefresh事件处理程序中的行,您可以执行以下操作

jQuery("#list").jqGrid('navGrid','#pager',
  { edit:false,view:false,add:false,del:false,search:false,
    beforeRefresh: function(){
        alert('In beforeRefresh');
        grid.jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid');
    }
  });

I modified an example from am old question. Hereif you click on the refresh button you can see live how the code work.

我修改了一个老问题的例子。在这里,如果您单击刷新按钮,您可以实时查看代码的工作方式。

UPDATED 2: Free jqGridsupports some new options. reloadGridevent supports fromServer: trueparameter which can be used to force reloading of data from the server and navGridsupports reloadGridOptionsoption which can be used to specify the options of reloadGridused on click on Refresh button. So the above code could be

更新 2免费 jqGrid支持一些新选项。reloadGrid事件支持fromServer: true可用于强制从服务器重新加载数据的参数,并navGrid支持reloadGridOptions可用于指定reloadGrid单击刷新按钮时使用的选项的选项。所以上面的代码可以是

$("#list").jqGrid("navGrid", {
    edit: false,
    add: false,
    del: false,
    search: false,
    reloadGridOptions: { fromServer: true }
});

By the way one can use navOptionsoption of jqGrid to specify default options of navGrid(see the wiki article). It allows to write the code something like

顺便说一句,可以使用navOptionsjqGrid 的选项来指定navGrid(请参阅维基文章)的默认选项。它允许编写类似的代码

$("#link").jqGrid({
    // all typical jqGrid parameters
    datatype: "json", // or "xml"
    loadonce: true,
    pager: true, // no empty div for page is required
    navOptions: {
        edit: false,
        add: false,
        del: false,
        search: false,
        reloadGridOptions: { fromServer: true }
    }
}).jqGrid("navGrid");

回答by Lihong Wei

I have tried the following config and it works.

我已经尝试了以下配置并且它有效。

<script type="text/javascript">
jQuery(function() {
    jq("#YOUR-GRID-ID").jqGrid({
        ...
        loadonce: true,
        ...
    });
    jQuery("#refresh_YOUR-GRID-ID").click(function(){
        jQuery("#YOUR-GRID-ID").setGridParam({datatype: 'json'});
        jQuery("#YOUR-GRID-ID").trigger("reloadGrid");
    });
});
</script>