Reputation: 162
I'm trying to extend the jqGrid "navgrid" method to add custom functionality (i.e adding a "navButtonAdd" or "filterToolbar") for ALL my table grids. I have about 100 pages, all working good with jqGrid v4.6.0, all with the same structure and already using "navGrid" method, and don't want to write "navButtonAdd" or "filterToolbar" in each page. So (according to Oleg's example in other answer), I first tried this:
/* this is my global.js file, which is included for every page, of course AFTER jquery.jqGrid.src.js */
var oldNavGrid = $.fn.jqGrid.navGrid;
$.jgrid.extend({
navGrid: function() {
var ret = oldNavGrid.call(arguments);
//... do something else, such navButtonAdd or filterToolbar...
return ret;
}
});
//...
/* this is the structure of every page */
var $myGrid = $("#$myGrid");
$myGrid.jqGrid({
//grid options...
})
$myGrid.jqGrid('navGrid', "#myPager",
{edit:false, add:true, del:true, search:true, refresh:true}, {}, {}, {}, {})
but when I call "navGrid" I get this error "Uncaught TypeError: undefined is not a function", pointing to jquery.jqGrid.src.js:8911
Then I tried different ways of overwriting, such
var oldNavGrid = $.fn.jqGrid.navGrid;
$.fn.jqGrid.navGrid = function() {
var ret = oldNavGrid.call(arguments);
//... do something else...
return ret;
};
always getting similar errors. Can someone tell me a solution for what I want to do? Thanks!!
Upvotes: 0
Views: 1198
Reputation: 221997
Try to use oldNavGrid.apply(this, arguments)
instead of oldNavGrid.call(arguments)
which don't forwards this
and uses arguments
as the first (and the only) parameter of navGrid
instead of forward all options. Alternatively you can use oldNavGrid.call(this, ...)
, but you need includes all parameters of navGrid explicitly instead of usage array-like object arguments
.
Upvotes: 2