当jqGrid中的'loadonce:true'时,触发器(“reloadGrid”)可以工作吗? [英] Can trigger(“reloadGrid”) works when 'loadonce: true' in jqGrid?

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

问题描述

我正在使用的jqGrid源文件在顶部显示为 jqGrid 4.4.0 ,日期为日期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页面它说触发器(oadGrid)

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

是的,它说只有在loadonce:false时它才能工作!

这个SO答案暗示了一些黑客。它说,

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

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

所以答案实际上解决了我面临的问题。我有一个jqGrid,它有 loadonce:true 。 (在这里我关心排序,它完美地工作)。但后来我不得不改变代码,用新的服务器数据重新加载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.

我打电话给你重新加载,

I called the reloading as this,

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

现在重装正常。但排序已经消失了:(

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

然后我看到了SO回答并将其更改为类似的内容,

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 ?

推荐答案

首先,我会严格建议您将从4.4.0版本使用的jqGrid升级到免费的jqGrid 4.12.1。免费的jqGrid是我从2014年底开始开发的jqGrid的分支。帖子和l有关其他信息,请参阅答案的更新部分。你应该明白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')

jqGrid支持本地内部数据保存JavaScript对象。可以使用数据类型:local,使用 data 参数提供数据,然后使用本地分页,排序和过滤数据。您可以更改页面大小( rowNum ),页码(页面)和排序参数(<$ c)的值通过触发<$ c $使用新选项$ c> sortname sortorder )和重新加载当前显示的页面 c> 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 用所有数据填充内部数据参数。 jqGrid显示返回数据的第一页(基于页面大小 rowNum 和页码页面)。最后(在处理 loadComplete 回调之后)jqGrid更改 datatype的原始值xml 在你的情况下)到数据类型:local。现在,用户可以使用本地分页,排序和过滤数据,而无需与服务器进行任何通信。在每个排序,分页和过滤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');

如果您的服务器正确实施,那么用户将看到所请求的数据页面,所有本地数据将要精神焕发。显示页面后,数据类型将更改回数据类型:'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.

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

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