Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
small improvment of the performance of working with jqGrid methods
09/12/2012
20:58
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hello Tony,

the code of jqGrid uses internally $.jgrid.no_legacy_api=true style of wotking with methods. It menas that one find everywhere in the code the calls like

$(ts).jqGrid("addSubGridCell",...)

see the line of code for example. Even if such calles will be done inside of loops the current style of accessing to jqGrid methods not allows to save one the functions addSubGridCell in a variable and call it directly inside of the loop's body.

I suggest to introduce very simple method getMethod

$.extend($.jgrid, {
    getMethod: function (name) {
        return $.jgrid.getAccessor($.fn.jqGrid, name);
    }
}); 

which get the reference to the method of jqGrid by string parameter (if needed one can include additional test whether the type of parameter is really string). If the method is not exist the method return undefined value.

Using the method one can rewrite above call of addSubGridCell in two parts. In the fisrt one at the beginning on the function (at the beginning of addJSONData function in the example) or directly before the loop one can use

var $self = $(ts),
    addSubGridCell = $.jgrid.getMethod("addSubGridCell");

to save the needed expressions in variables and then use

addSubGridCell.call($self,...)

instead of

$(ts).jqGrid("addSubGridCell",...)

The code will stay readable, but the performance will be improved.

Additionally one can add explicit test for undefined parameter (call without parameters) in the part of code:

$.fn.jqGrid = function( pin ) {
    if (typeof pin === 'string') {
        //var fn = $.fn.jqGrid[pin];
        var fn = $.jgrid.getMethod(pin);
        if (!fn) {
            throw ("jqGrid - No such method: " + pin);
        }
        var args = $.makeArray(arguments).slice(1);
        return fn.apply(this,args);
    }
    if (pin === undefined) {
        // allow the usage of jqGrid methods in the form $("#list").jqGrid().method(params)
        // for example
        //    $("#list").jqGrid().getGridParam("colModel")
        // So one can save $("#list").jqGrid() in a variable
        //    var $self = $("#list").jqGrid();
        // and one can use simplified form of method calls,
        // exactly like in case of no_legacy_api=false:
        //    var localRowData = $self.getLocalRow(rowid);
        return $.extend({}, this, $.fn.jqGrid);
    }

    return this.each( function() {
        ... 

Best regards

Oleg

10/12/2012
12:27
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Oleg,

This is very interesting. Will perform tests in order to get feedback.

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

28/12/2012
12:46
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello Oleg,

I have implemented your idea, extended to grouping too (code is in GitHub). Also i do not think that we need the code when the pin=undefined.

We can easy do (after the grid is created)

var $gird = $("#grid") and then use use it  or

var $gird = $("#grid").jqGrid({…}) when it is created.

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
13 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information