architect
26 Sep 2007, 10:41 PM
Hi
I have a legacy application which output xml. The request to retrieve the first set of data is http://server/search.jsp?a=xxx&start=1&count=15.
I have a problem with the initial start value in pagingtoolbar. If I set start to 1 in ds.load, the page number is 2 instead of 1.
How can I modify the pagenumber computation?
Thanks
Extjs 1.1.1
architect
1 Oct 2007, 4:11 AM
to solve the problem, i have to extend Ext.PagingToolbar like this:
Ext.AIPagingToolbar = function(el, ds, config){
Ext.PagingToolbar.superclass.constructor.call(this, el, null, config);
this.ds = ds;
this.cursor = 1;
this.renderButtons(this.el);
this.bind(ds);
};
Ext.extend(Ext.AIPagingToolbar, Ext.PagingToolbar, {
updateInfo : function(){
if(this.displayEl){
var count = this.ds.getCount();
var msg = count == 0 ?
this.emptyMsg :
String.format(
this.displayMsg,
this.cursor, this.cursor+count-1, this.ds.getTotalCount()
);
this.displayEl.update(msg);
}
},
getPageData : function(){
var total = this.ds.getTotalCount();
return {
total : total,
activePage : Math.ceil((this.cursor-1+this.pageSize)/this.pageSize),
pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
};
},
onPagingKeydown : function(e){
var k = e.getKey();
var d = this.getPageData();
if(k == e.RETURN){
var v = this.field.dom.value, pageNum;
if(!v || isNaN(pageNum = parseInt(v, 10))){
this.field.dom.value = d.activePage;
return;
}
pageNum = Math.min(Math.max(1, pageNum), d.pages)-1;
this.ds.load({params:{start: (pageNum * this.pageSize)+1, count: this.pageSize}});
e.stopEvent();
}
else if(k == e.HOME || (k == e.UP && e.ctrlKey) || (k == e.PAGEUP && e.ctrlKey) || (k == e.RIGHT && e.ctrlKey) || k == e.END || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey))
{
var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
this.field.dom.value = pageNum;
this.ds.load({params:{start: ((pageNum - 1) * this.pageSize)+1, count: this.pageSize}});
e.stopEvent();
}
else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
{
var v = this.field.dom.value, pageNum;
var increment = (e.shiftKey) ? 10 : 1;
if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
increment *= -1;
if(!v || isNaN(pageNum = parseInt(v, 10))) {
this.field.dom.value = d.activePage;
return;
}
else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
{
this.field.dom.value = parseInt(v, 10) + increment;
pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
this.ds.load({params:{start: (pageNum * this.pageSize) +1, count: this.pageSize}});
}
e.stopEvent();
}
},
onClick : function(which){
var ds = this.ds;
switch(which){
case "first":
ds.load({params:{start: 1, count: this.pageSize}});
break;
case "prev":
ds.load({params:{start: Math.max(1,
this.cursor-this.pageSize), count: this.pageSize}});
break;
case "next":
ds.load({params:{start: this.cursor+this.pageSize,
count: this.pageSize}});
break;
case "last":
var total = ds.getTotalCount();
var extra = total % this.pageSize;
var lastStart = extra ? (total - extra) : total-this.pageSize;
ds.load({params:{start: lastStart +1, count: this.pageSize}});
break;
case "refresh":
ds.load({params:{start: this.cursor, count: this.pageSize}});
break;
}
}
});
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.