开发者

How can I add on to default events in jqGrid?

I have common code that I w开发者_运维百科ant in various events for our standard jqGrid configuration.

I use $.extend($.jgrid.defaults, { }); to set some code for the following:

  • loadError()
  • beforeRequest()
  • loadComplete()
  • gridComplete()

Now, when I define an instance of my grid, there is a potential that I would like to execute more code in any of these events.

My initial solution was to have global variables, e.g.: loadCompleteEx() and if they are defined, call them at the end of the default method calls. This was great if I only had one grid on the page, but I am trying to implement a solution that would work regardless of how many grids are on the page.

Is there some way to hook in and add a method to execute when any of these events are fired? I'm using jqGrid 4.1.2 and jQuery 1.6.

Thanks in advance for your help!


You can .bind() your own functions to events, so that your function executes with the event. You could use this to bind different events to each grid, or bind one function to every grid at once.

.bind() also allows binding to standard javascript events, custom events, or even undefined strings which you later call with .trigger().

It needs to be attached after a selector, which can select a specific grid or multiple grids in your case.

$('#Your-Grid-Selector').bind('eventToBind', functiontoBind() {
            alert('Triggered eventToBind');
        });

jQuery Documentation

Edit: This question may be a duplicate of this SO Question, which has a good solution you can use for this very issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜