jQuery jqgrid reloadGrid 与 loadonce 设置为 true

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5397671/
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 19:06:44  来源:igfitidea点击:

jqgrid reloadGrid with loadonce set to true

jqueryjqgrid

提问by Sam

I am using two jqgrids in one page. second grid i used loadonce: truesince i need column sort in the second grid. i need to reload both grids after a server post back. (need to show updated value in the second grid). first grid reload fine since it won't use the loadonceattribute. my question is can we use loadonceattribute and reloadGridtogether? ( by setting loadonceattribute dynamically to the grid) or else do i need to go for a server side sorting in this case? please advice. Thanks in advance.

我在一页中使用了两个 jqgrid。我使用的第二个网格,loadonce: true因为我需要在第二个网格中进行列排序。我需要在服务器回发后重新加载两个网格。(需要在第二个网格中显示更新的值)。第一个网格重新加载很好,因为它不会使用该loadonce属性。我的问题是我们可以一起使用loadonce属性reloadGrid吗?(通过loadonce为网格动态设置属性)或者在这种情况下我是否需要进行服务器端排序?请指教。提前致谢。

回答by Oleg

If you use loadonce:truejqGrid change the datatypeparameters to 'local' after the first load of data from the grid. All next grid reloading (sorting, paging, filtering) works local. If you want refresh the grid data from the server one more time you should set datatypeto its original value ('json' or 'xml'). For example:

如果您使用loadonce:truejqGrid datatype,请在第一次从网格加载数据后将参数更改为“本地”。所有接下来的网格重新加载(排序、分页、过滤)都在本地进行。如果您想再刷新一次来自服务器的网格数据,您应该设置datatype为其原始值('json' 或 'xml')。例如:

$("#list").setGridParam({datatype:'json', page:1}).trigger('reloadGrid');

UPDATED:Free jqGridsupports fromServer: trueoption of reloadGridstarting with the first release (starting with version 4.8). So one can use the code like

更新:免费 jqGrid支持从第一个版本开始的fromServer: true选项reloadGrid(从 4.8 版开始)。所以可以使用像这样的代码

$("#list").trigger("reloadGrid", { fromServer: true, page: 1 });

to do the same as above. The main advantage: such code works fine with any initial value of datatype("json", "jsonp", "xml"and so on). Free jqGrid saves original value of datatypeinside of internal dataTypeOrgbefore changing it to "local".

做与上面相同的事情。主要优点:这样的代码工作正常的任何初始值datatype"json""jsonp""xml"等等)。免费的jqGrid节省的原始值datatype的内部内dataTypeOrg将其更改为之前"local"

One more helpful option of free jqGrid is the parameter reloadGridOptionsof navGrid, which allows to specify default options of reloadGrid. Thus one can use for example

免费的jqGrid的一个更有帮助选项参数reloadGridOptionsnavGrid,它允许指定的默认选项reloadGrid。因此可以使用例如

loadonce: true,
navOptions: { reloadGridOptions: { fromServer: true } }

options of jqGrid, which set defaults for navGridadditionally. As the result the click on "Reload" button of navigator bar will reload the grid from the server instead of local reloading.

jqGrid 的选项,navGrid另外设置默认值。因此,单击导航栏的“重新加载”按钮将从服务器重新加载网格,而不是本地重新加载。

回答by Kiran Jujare

Nice was trying for last one week , solution is perfect use

尼斯尝试了上周,解决方案是完美的使用

jQuery("#datalist").jqGrid().setGridParam(
    {
        datatype:'xml', 
        page:1, 
        url : '<%=request.getContextPath()%>/PreviewReport?cmd=1&fromdate='+vfromDate+'&todate='+vtoDate+'&status='+vstatus+'&keyword='+vkeyword+'&mdn='+vmdn+'&filetype='+vfiletype
    }
).trigger("reloadGrid");

to reload the data using loadonce:false

使用重新加载数据 loadonce:false

回答by Mike Gledhill

Just to say, for me, the following line wasn't enough, to refresh the data in my loadonce:truejqGrid:

只是说,对我来说,以下行还不够,刷新我的loadonce:truejqGrid 中的数据:

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

After calling that line, I tried to call my code which loaded my JSON data and populated the jqGridwith it, but it didn't refresh the rows in my grid.

调用该行后,我尝试调用加载我的 JSON 数据并填充jqGrid它的代码,但它没有刷新网格中的行。

My solution was to forcibly unloadthe jqGrid, and thencall my function to recreate it.

我的解决办法是强行卸载jqGrid,然后调用我的函数重新创建。

$("#MikesGrid").jqGrid('GridUnload');

Perhaps I was just unlucky.

也许我只是运气不好。

Btw, when I get a chance, I'll document how I wrote a generic JavaScript function to add two buttons to any jqGrid, one to refresh the (loadonce) data, and a second button to export the jqGrid data into a real Excel file, using my library:

顺便说一句,当我有机会时,我将记录我如何编写一个通用 JavaScript 函数来向任何 jqGrid 添加两个按钮,一个用于刷新(加载一次)数据,第二个按钮用于将 jqGrid 数据导出到真正的 Excel 文件中,使用我的图书馆:

Export jqGrid to an Excel file

将 jqGrid 导出到 Excel 文件

I like reuseable code !

我喜欢可重用的代码!

回答by Naga Veerendra Parvataneni

$("#shoppingCatalog").jqGrid('GridUnload');

Will remove the structure and then your code can rebuild the grid with the data from the next server call-back.

将删除结构,然后您的代码可以使用来自下一个服务器回调的数据重建网格。