This question originated after I looked on this answer of Oleg and demo-grids in it.
gridComplete
:
This fires after all the data is loaded into the grid and all other processes are complete. Also the event fires independent from the datatype parameter and after sorting paging and etc.
loadComplete
:
This event is executed immediately after every server request. data Data from the response depending on datatype grid parameter
From that docs I understood that gridComplete
fires at the end of drawing grid, and loadComplete
fires after jqGrid completes communication with backend.
And so I wonder - why in demos, loadComplete
used for change color of cells and not gridComplete
?
I think that this question is asked by many users of jqGrid. So it's interesting to know the answer.
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
.
Here are advantages of loadComplete
:
loadComplete
has parameter data
which represent full page of local data or full data loaded from the server. 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.
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
.
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
.
Looking at the source of jqGrid (source) you can see that gridComplete is called on just one line of grid.base.
1725: if($.isFunction(ts.p.gridComplete)) {ts.p.gridComplete.call(ts);}
This line comes from the function updatePager
.
You can find loadComplete
in the populate
function (line 1757). Unlike gridComplete
, it is passed an extra parameter. Both callbacks receive a reference to this
, but loadComplete
also receives the data returned from the server (or passed in locally):
1858: case "xmlstring":
if(lcf) {ts.p.loadComplete.call(ts,dstr);}
1869: case "jsonstring":
if(lcf) {ts.p.loadComplete.call(ts,dstr);}
1881:
case "local":
case "clientside":
if(lc) { lc.call(ts,req); }
The thing is, the functions populate
and updatePager
often happen in tandem, so you see that when sorting and paging, both callbacks are called. The difference, once again, is that loadComplete
is passed an extra parameter.
There are probably subtle differences that I haven't encountered yet... and there might be cases where one is called and the other isn't, but I have noticed that on sorting and paging, both are called.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.