当' loadonce:true'可以触发("reloadGrid")工作在jqGrid中? [英] Can trigger(“reloadGrid”) works when 'loadonce: true' in jqGrid?

查看:90
本文介绍了当' loadonce:true'可以触发("reloadGrid")工作在jqGrid中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用的jqGrid源文件在顶部说它的版本是 jqGrid 4.4.0 ,日期是 Date 2012-06-14

The jqGrid source file I'm using says at the top it's version as jqGrid 4.4.0 , date as Date 2012-06-14

在此 Wiki页面中,它表示 trigger("reloadGrid")

使用当前设置重新加载网格.这意味着如果数据类型为xml或json,则将新请求发送到服务器.此方法应应用于已经构造的网格.请注意,此方法不会更改HEADER信息,这意味着对colModel的任何更改都不会受到影响.您应该使用gridUnload使用不同的colModel重新加载新配置.仅在loadonce时有效:false !!!

是的,它说只有在loadonce时才起作用:false !!!"

这样的答案提出了一些建议为了那个原因.它说,

And this SO answer suggest some hack for that. It says,

如果使用loadonce:true,则jqGrid在第一次从网格加载数据后将数据类型参数更改为"local".接下来的所有网格重新加载(排序,分页,过滤)都在本地进行.如果要再次从服务器刷新网格数据,则应将数据类型设置为其原始值("json"或"xml").

这样的答案实际上解决了我面临的一个问题.我有一个具有 loadonce:true 的jqGrid.(这里我关心的是排序,它工作得很好).但是随后我不得不稍微修改一下代码,以使用新的服务器数据重新加载jqGrid.(用户可以更改一些详细信息并刷新表,以便jqGrid应该从服务器重新加载新获取的数据).不幸的是,直到我将 loadonce:true 更改为 loadonce:false 后,此方法才起作用.

So that answer actually solved a problem I was facing. I had a jqGrid which has loadonce:true. (here I care about the sorting and it worked perfectly). but then I had to change the code a bit to reload the jqGrid with new server data. (user can change some details and refresh the table so the jqGrid should reload the newly aquired data from the server). Unfortunately this didn't work until I changed loadonce:true to loadonce:false.

我这样称呼重装

$("#tableGrid").setGridParam({url:'myUrl'}).trigger('reloadGrid');

现在重新加载就可以了.但排序不见了:(

Now the reloading was fine. BUT the sorting was gone :(

然后我看到了这样的答案,并将其更改为这样的内容,

And then I saw that SO answer and change it to something like this,

我在初始化网格时设置了 loadonce:true .并按如下方式进行重新加载.

I set loadonce:true when initializing the grid. and called the reloading as below.

$("#tableGrid").setGridParam({url:'myUrl',datatype:'xml'}).trigger('reloadGrid');

之后,所有排序都很好,用户也可以重新加载网格.

after that all the sorting was fine and user can reload the grid as well.

这种方法正确吗?我认为它解决了问题,是吗?,因为文档说您不能在 loadonce:true 时重新加载?

Is this approach correct ? I think it solved the problem, but is it ? because the documentation says you can't reload when loadonce:true ?

推荐答案

首先,我强烈建议您将使用的jqGrid从版本4.4.0升级到答案的UPDATED部分中的链接有关其他信息.您应该了解jqGrid 4.4.0确实是复古版本.它在jQuery 1.4.3版本发布时发布.当时是IE9是Internet Explorer的最新版本,但IE6-IE8是最常用的版本.现在,我们在Web开发中还有一个时间.

First of all I would strictly recommend you to upgrade jqGrid which you use from version 4.4.0 to free jqGrid 4.12.1. Free jqGrid is the fork of jqGrid which I develop starting with end of 2014. See the post and the link from UPDATED part of the answer for additional information. You should understand that jqGrid 4.4.0 is really retro version. It was published at the time of jQuery 1.4.3 version. It was the time when IE9 was the latest version of Internet Explorer, but IE6-IE8 was the mostly used versions. Now we have another time in web development.

重要的是要了解 loadonce:true .trigger('reloadGrid')的作用.

It's important to understand what do loadonce: true and what do .trigger('reloadGrid').

jqGrid支持在JavaScript对象内部本地保存数据.可以使用 datatype:"local" ,使用 data 参数提供数据,然后使用 local 分页对数据进行处理,排序和过滤数据.您可以更改页面大小( rowNum ),页面编号( page )和排序参数( sortname sortorder ),并使用新选项通过触发 reloadGrid 事件重新加载当前显示的页面.jqGrid将对数据进行排序并显示请求的页面.因此,重要的是要了解 .trigger('reloadGrid')也适用于本地数据.

jqGrid support local holding of data inside of JavaScript objects. One can use datatype: "local", provides the data using data parameter and then work with the data using local paging, sorting and filtering the data. You can change the values of page size (rowNum), page number (page) and sorting parameters (sortname, sortorder) and reload the current displayed page using the new options by triggering reloadGrid event. jqGrid will sort the data and displays the requested page. Thus it's important to understand that .trigger('reloadGrid') works with local data too.

如果您将 datatype:'xml' loadonce:true 一起使用,则服务器必须返回所有数据.数据只能按请求的 sortname sortorder 选项进行排序(请求的参数 sidx sord 到服务器).因此,jqGrid 用所有数据填充内部 data 参数.jqGrid显示返回数据的第一页(基于页面大小 rowNum 和页面编号 page ).最后(在处理了 loadComplete 回调之后),jqGrid将 datatype (如果您是"xml" )的原始值更改为 datatype:本地" .现在,用户可以使用本地分页,排序和过滤数据,而无需与服务器进行任何通信.在每次排序,分页和筛选时,jqGrid都会使用 reloadGrid 事件显示相应的数据页面.

If you use datatype:'xml' together with loadonce: true then the server have to return all data. The data have to be sorted by requested sortname, sortorder options only (the parameters sidx and sord of the request to the server). Thus jqGrid fills internal data parameter with all the data. jqGrid displays the first page of returned data (based on page size rowNum and page number page). Finally (after processing loadComplete callback) jqGrid changes the original value of datatype ("xml" in you case) to datatype: "local". Now the user can use local paging, sorting and filtering the data without any communication with the server. On every sorting, paging and filtering jqGrid uses reloadGrid event to display the corresponding page of data.

如果需要从服务器重新加载数据,则只需恢复 datatype 参数的原始值并触发 reloadGrid .例如

If you need to reload the data from the server then you need just restore the original value of datatype parameter and trigger reloadGrid. For example

$("#tableGrid").setGridParam({datatype:'xml'}).trigger('reloadGrid');

如果服务器实施正确,则用户将看到请求的数据页面,并且将刷新所有本地数据.显示页面后,数据类型将更改回 datatype:'local'.

If your server is correctly implemented then the user will see the requested page of data and all local data will be refreshed. The datatype will be changed back to datatype:'local' after displaying the page.

如果您使用当前的免费jqGrid,则可以使用以下选项

If you use the current free jqGrid then you can use the following options

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

选项 forceClientSorting:true 从服务器中删除了提供排序数据的要求.免费的jqGrid可以对从服务器返回的数据进行排序.如果使用 navGrid ,则会添加刷新"/重新加载"按钮.选项 navOptions:{reloadGridOptions:{fromServer:true}} 更改按钮的行为,以便在用户单击按钮时从服务器重新加载数据.无需手动更改数据类型.

The option forceClientSorting: true removes from the server the requirement to provide sorted data. Free jqGrid can sort the data returned from the server. If you use navGrid then it adds "Refresh"/"Reload" button. The option navOptions: { reloadGridOptions: { fromServer: true } } changes the behavior of the button so, that the data will be reloaded from the server if the user clicks on the button. No manual changing of datatype is not needed.

这篇关于当' loadonce:true'可以触发("reloadGrid")工作在jqGrid中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆