PDA

View Full Version : PagingToolBar: extension - add public method - goToPage()



jay@moduscreate.com
20 Oct 2007, 11:12 AM
I didn't know what to call it, so i called it 'CustomToolBar'. i looked at the source, didn't see anything like it.



// Create user extensions namespace (Ext.ux)
Ext.namespace('Ext.ux');

Ext.ux.CustomToolBar = function(config) {
// call parent constructor
Ext.ux.CustomToolBar.superclass.constructor.call(this, config);

}

// extend
Ext.extend(Ext.ux.CustomToolBar, Ext.PagingToolbar, {
goToPage : function (pageNum) {
var d = this.getPageData();
pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
this.doLoad(pageNum * this.pageSize);
}
}); // end of extend


usage:

var paging = new Ext.ux.CustomToolBar ({your config data});
// Jump to page
paging.goToPage(int);

JeffHowden
21 Oct 2007, 11:18 AM
If the only reason you're extending the PagingToolbar is to add a new method to it, why not just use an override?


Ext.PagingToolbar.override({
goToPage : function (pageNum) {
var d = this.getPageData();
pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
this.doLoad(pageNum * this.pageSize);
}
});

jay@moduscreate.com
21 Oct 2007, 4:56 PM
ack, you're right! meh! i forgot about .override :)

Thanks jeff. :)

JeffHowden
21 Oct 2007, 5:47 PM
Always happy to help (especially those with a much higher post count than mine ;)).

jay@moduscreate.com
22 Oct 2007, 3:03 AM
Why are folks worried about post count around here?

JeffHowden
22 Oct 2007, 7:42 AM
No reason. I only brought it up cause I saw someone give you grief about it a few days ago. ;)

jay@moduscreate.com
22 Oct 2007, 8:05 AM
http://www.xtremepccentral.com/forums/images/smilies/lolfall.gif good one. \:D/