问题描述
这个问题是在我查看了 this 的回答后提出的users/315935/oleg">Oleg 和其中的演示网格.
This question originated after I looked on this answer of Oleg and demo-grids in it.
gridComplete
:
在所有数据加载到网格和所有其他数据后触发过程完成.该事件也独立于数据类型参数和排序后分页等
loadComplete
:
此事件在每次服务器请求后立即执行.数据来自响应的数据取决于数据类型网格参数
从那个文档我了解到 gridComplete
在绘图网格结束时触发,而 loadComplete
在 jqGrid 完成与后端的通信后触发.
From that docs I understood that gridComplete
fires at the end of drawing grid, and loadComplete
fires after jqGrid completes communication with backend.
所以我想知道 - 为什么在演示中,loadComplete
用于改变单元格的颜色而不是 gridComplete
?
And so I wonder - why in demos, loadComplete
used for change color of cells and not gridComplete
?
推荐答案
我想这个问题是 jqGrid 的很多用户都问过的.所以知道答案很有趣.
I think that this question is asked by many users of jqGrid. So it's interesting to know the answer.
我个人更喜欢使用 loadComplete
.如果您检查我发布的所有示例中的代码,您会发现 gridComplete
只有当原始海报将其发布在问题中并且我会修改一些代码时.我更喜欢使用 loadComplete
因为 loadComplete
的一些优点和 gridComplete
的缺点.
I personally prefer to use loadComplete
. If you examine code from all my examples which I posted, you will find gridComplete
only when the Original Poster posted it in the question and I would have modified a little code. I prefer to use loadComplete
because of some advantages of loadComplete
and disadvantages of gridComplete
.
以下是 loadComplete
的优点:
- 这是最后一个回调,如果整个网格体将被重新加载,则将调用该回调.例如在从服务器加载网格上的页面之后.重要的是要了解,如果用户更改某些列的排序或设置过滤器或选择网格的另一页;网格体将被重新加载.
loadComplete
有参数data
表示本地数据的完整页面或从服务器加载的完整数据.
- It's the last callback which will be called if the whole grid body will be reloaded. For example after loading the page on the grid from the server. It's important to understand, that if the user changes sorting of some column or sets filter or chooses another page of the grid; the grid body will be reloaded.
loadComplete
has parameterdata
which represent full page of local data or full data loaded from the server.
另一方面 gridComplete
将从内部 updatepager
调用(在当前版本的 jqGrid 4.4.4 中)(参见 此处),将从 delRowData(参见此处),
addRowData
(见 此处)和clearGridData
(参见此处) 方法;除了addXmlData
(参见此处)和 addJSONData
(参见 此处).这不是人们最想要的.
On the other side gridComplete
will be called (in the current version of jqGrid 4.4.4) from internal updatepager
(see here), which will be called from delRowData
(see here), addRowData
(see here) and clearGridData
(see here) methods; in addition to addXmlData
(see here) and addJSONData
(see here). It's not what one mostly want.
gridComplete
的另一个缺点是可以查看是否检查 addXmlData
的代码(参见 此处)和addJSONData
(请参阅这里) 从哪里 updatepager
被调用,所以 gridComplete
将被调用.如果使用 loadonce: true
并且内部参数 data
和 _index
将填充从服务器返回的完整数据.使用 loadonce: true
时可以看到;回调gridComplete
会在服务器加载第一页数据后调用.此时data
和_index
只包含页面的数据.另一方面,loadComplete
将在服务器返回的所有数据处理完毕并保存在本地后调用 data
和 _index代码>.
Another disadvantage of gridComplete
one can see if one examines the code of addXmlData
(see here) and addJSONData
(see here) from where updatepager
is called and so gridComplete
will be called. If one uses loadonce: true
and the internal parameters data
and _index
will be filled with full data returned from the server. One can see when using loadonce: true
; the callback gridComplete
will be called after the first page of data are loaded from the sever. At this moment data
and _index
contains only the data for the page. On the other side loadComplete
will be called later after all data returned from the server are processed and saved locally in data
and _index
.
如果您从服务器加载数据并且如果您不使用 loadonce: true
选项、clearGridData
、addRowData
和 >delRowData
那么你可以使用 gridComplete
而不是 loadComplete
.
If you load the data from the server and if you don't use loadonce: true
option, clearGridData
, addRowData
and delRowData
then you could use gridComplete
instead of loadComplete
.
这篇关于loadComplete 和 gridComplete 事件有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!