Fred A
Fred A

Reputation: 1764

Adding functions into existing JqGrid events

So my application uses multiple grids, but i separated the codes into 2 files, for one that is unique to the grid, and one more for common functions that are shared across all grids.

Now the thing is, i defined some of the events in the unique files, like for example, i defined loadComplete event in one of the grid only file because the functions are unique for that grid only and not for other grids. But now when i tried to add common loadComplete functions that apply to all grids in the common functions file, it wouldn't work for me.

I can make it work if i defined that common functions in every loadComplete but then that would defeat the purpose of separating unique-to-the-grid functions in one file and shared functions in another file (for maintaining purpose).

So i'd like to know is there any way to add extra functions in loadComplete event in the common functions file, when the loadComplete event has already been applied in every file that is unique to the grid itself.

I tried with the following examples i got from here but none seems to work for me

$.jqgrid.extend({})

$(function() {})

(function($){})

jQuery.extend(jQuery.jgrid.defaults, {})

Upvotes: 1

Views: 929

Answers (1)

Oleg
Oleg

Reputation: 221997

If you carefully read of my answers you will see that I use a little other terminology as the official jqGrid documentation. I name loadComplete as callback function instead of event handler. One can define only once callback function loadComplete. On the other side one can use jQuery events like jqGridLoadComplete (see here) which introduced in version 4.3.2 of jqGrid. By the way the corresponding modification of jqGrid code be made by me. I posted many pull requests with all events.

You can find the fragment of usage jqGridLoadComplete event in the answer. By the way you can bind the event jqGridLoadComplete to empty <table> element before the grid is created. Only if you do so you will be sure that the jqGridLoadComplete will be fired even for the initial filling of the grid.

The main advandage of usage jQuery events like jqGridLoadComplete: one can define multiple event handles. So you can implement the scenario which you need. By the way there are exist jqGridAfterLoadComplete event too. First will be fired jqGridLoadComplete event and all event handlers will be executed, then will be called loadComplete callback and finally the jqGridAfterLoadComplete event will be fired. You should decide yourself which one (jqGridLoadComplete or jqGridAfterLoadComplete) is better for the scenario which you implement.

Upvotes: 1

Related Questions