Forum
20:58
10/08/2009
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
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
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
addSubGridCell = $.jgrid.getMethod("addSubGridCell");
to save the needed expressions in variables and then use
instead of
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:
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
12:27
Moderators
30/10/2007
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.
12:46
Moderators
30/10/2007
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.
Most Users Ever Online: 715
Currently Online:
45 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.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66