(function() {
var T = Ext.Toolbar;
Ext.PM3PagingToolbar=Ext.extend(Ext.Toolbar, {
emptyMsg: '没有数据显示.',
displayMsg : '显示 {0} - {1} 总数 {2}',
prevText: '上一页',
nextText: '下一页',
targetPageText: '跳转目标页',
/**
* 对称长度
*/
symmetryLength: 3,
initComponent: function() {
this.userItems = this.items || this.buttons || [];
var pagingItems = [
this.prev = new T.Button({
itemId: 'prev',
tooltip: this.prevText,
overflowText: this.prevText,
iconCls: 'x-tbar-page-prev',
disabled: true,
handler: this.movePrevious,
scope: this
}),
this.next=new T.Button({
itemId: 'next',
tooltip: this.nextText,
overflowText: this.nextText,
iconCls: 'x-tbar-page-next',
disabled: true,
handler: this.moveNext,
scope: this
})
];
this.items = pagingItems.concat(this.userItems);
if(this.displayInfo){
this.items.push('->');
this.items.push(this.displayItem = new T.TextItem({}));
}
Ext.PM3PagingToolbar.superclass.initComponent.call(this);
this.cursor = 0;
if(isNaN(this.symmetryLength) || this.symmetryLength < 0) {
this.symmetryLength = 0;
}
this.bindStore(this.store, true);
},
bindStore: function(store, initial) {
if(!initial && this.store) {
if(store !== this.store && this.store.autoDestroy){
this.store.destroy();
}else{
this.store.un('load', this.onLoad, this);
}
if(!store){
this.store = null;
}
}
if(store) {
store = Ext.StoreMgr.lookup(store);
store.on({
scope: this,
load: this.onLoad
});
doLoad = true;
this.pageSize = store.baseParams['limit'];
}
this.store = store;
},
onLoad: function(store, r, o) {
if(!this.rendered){
this.dsLoaded = [store, r, o];
return ;
}
var p = this.getParams();
this.cursor = (o.params && o.params[p.start]) ? o.params[p.start] : 0;
var d = this.getPageData(), ap = d.activePage, ps = d.pages;;
this.prev.setDisabled(ap == 1);
this.next.setDisabled(ap == ps);
this.updateInfo();
this.buildPages();
},
getParams: function() {
return this.paramNames || this.store.paramNames;
},
doLoad: function(start) {
var o = {}, pn = this.getParams();
o[pn.start] = start;
o[pn.limit] = this.pageSize;
this.store.load({params:o});
},
movePrevious: function() {
this.doLoad(Math.max(0, this.cursor-this.pageSize));
},
moveNext: function() {
this.doLoad(this.cursor+this.pageSize);
},
moveTo: function(page) {
this.doLoad((page-1)*this.pageSize);
},
updateInfo : function(){
if(this.displayItem){
var count = this.store.getCount();
var msg = count == 0 ?
this.emptyMsg :
String.format(
this.displayMsg,
this.cursor+1, this.cursor+count, this.store.getTotalCount()
);
this.displayItem.setText(msg);
}
},
getPageData : function(){
var total = this.store.getTotalCount();
return {
total : total,
activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
};
},
buildPages: function() {
this.removePages();
var d = this.getPageData();
//d.pages = 100;
var pageCursor = d.activePage;
var leftStart = d.activePage - this.symmetryLength - 1;
var prevIndex = this.getItemIndex('prev');
//左边 123456789
while(pageCursor > leftStart && pageCursor > 0) {
if(pageCursor == d.activePage) {
this.insert(prevIndex+1, {xtype: 'tbtext', text: '<span style="color: red;cursor: pointer;font-size: 14px;">'+pageCursor+'</span>'});
} else {
this.insert(prevIndex+1, new T.Button({text: '<span style="font-size: 14px;">'+pageCursor.toString()+'</span>', page: pageCursor, handler: function(t, e) {
this.moveTo(t.page);
}, scope: this}));
}
pageCursor--;
}
if(pageCursor >= 1) {
if(pageCursor > 1 && this.symmetryLength > 0) {
this.insert(prevIndex+1, {itemId: 'frontIgnore', width: 32, tooltip: this.targetPageText, overflowText: this.targetPageText, text: '<span style="cursor: pointer;">......</span>', handler: function(t, e) {
if(this.getItemIndex('backIgnore') > -1) {
this.items.get(this.getItemIndex('backIgnore')).setVisible(true);
}
var frontIndex = this.getItemIndex(t.getItemId());
this.insert(frontIndex, this.getInputItem());
t.setVisible(false);
this.getInputItem().focus(true);
}, scope: this});
pageCursor = 1;
}
this.insert(prevIndex+1, {text: '<span style="font-size: 14px;">'+pageCursor.toString()+'</span>', handler: function() {
this.moveTo(1);
}, scope: this});
}
// 右边
pageCursor = d.activePage + 1;
var rightEnd = d.activePage + this.symmetryLength;
var nextIndex = this.getItemIndex('next');
while(pageCursor <= rightEnd && pageCursor <= d.pages) {
this.insert(nextIndex++, {text: '<span style="font-size: 14px;">'+pageCursor.toString()+'</span>', page: pageCursor, handler: function(t, e) {
this.moveTo(t.page);
}, scope: this});
pageCursor++;
}
if(pageCursor <= d.pages) {
if(pageCursor < d.pages && this.symmetryLength > 0) {
this.insert(nextIndex++, {itemId: 'backIgnore', width: 32, tooltip: this.targetPageText, overflowText: this.targetPageText, text: '<span style="cursor: pointer;">......</span>', handler: function(t, e) {
if(this.getItemIndex('frontIgnore') > -1) {
this.items.get(this.getItemIndex('frontIgnore')).setVisible(true);
}
var backIndex = this.getItemIndex(t.getItemId());
this.insert(backIndex, this.getInputItem());
t.setVisible(false);
this.getInputItem().focus(true);
}, scope: this});
pageCursor = d.pages;
}
this.insert(nextIndex++, {text: '<span style="font-size: 14px;">'+pageCursor.toString()+'</span>', handler: function() {
this.moveTo(d.pages);
}, scope: this});
}
},
removePages: function() {
var start = this.getItemIndex('prev'),
end = this.getItemIndex('next');
this.items.each(function(item, i) {
if(i > start && i < end) {
this.remove(item);
}
}, this);
this.inputItem = null;
},
getItemIndex: function(itemId) {
var index = 0;
this.items.each(function(item, i) {
if(item.getItemId()==itemId) {
index = i;
return false;
}
});
return index;
},
getInputItem: function() {
if(!this.inputItem) {
this.inputItem = new Ext.form.NumberField({
cls: 'x-tbar-page-number',
allowDecimals: false,
allowNegative: false,
enableKeyEvents: true,
selectOnFocus: true,
submitValue: false,
width: 32,
listeners: {
scope: this,
keydown: this.onPagingKeyDown,
blur: function() {
this.removeInputItem();
}
}
});
}
return this.inputItem;
},
removeInputItem: function() {
this.remove(this.getInputItem());
this.inputItem = null;
if(this.getItemIndex('frontIgnore') > -1) {
this.items.get(this.getItemIndex('frontIgnore')).setVis
没有合适的资源?快使用搜索试试~ 我知道了~
ExtJS 自定义分页控件---- PM3PagingToolbar.js
共4个文件
jpg:3个
js:1个
4星 · 超过85%的资源 需积分: 50 111 下载量 19 浏览量
2011-10-28
16:53:02
上传
评论 4
收藏 24KB RAR 举报
温馨提示
非传统分页工具. 简单说明下: 显示第一页与最后一页. 显示当前页对称的前后几页(可以自定义显示多少页). 其它的页码省略. 点击省略号, 省略号隐藏, 显示一个与省略号相同宽度的页面跳转转入框. 整个设置还比较智能. 在 ExtJS3.3基础上开发的. 低一点的版本应该也能用. 没有去测试. 参考: Ext.PagingToolbar.js 如有BUG还请各位提出或留言. 附件中有图片, 一看就知道. 用法: var grid = new Ext.grid.GridPanel({ bbar: new Ext.PM3PagingToolbar({ store : store, displayInfo : true, displayMsg: '显示 {0} - {1} 行 总数 {2} 行', emptyMsg : '没有数据显示' }) }); store必须设置 baseParams 的 limit 的值.
资源推荐
资源详情
资源评论
收起资源包目录
PM3PagingToolbar.rar (4个子文件)
2.jpg 13KB
1.jpg 13KB
PM3PagingToolbar.js 8KB
3.jpg 15KB
共 4 条
- 1
资源评论
- zxfaihy992012-02-29用不了啊,程序有错误啊。
- xiaosongol2013-09-11用不了啊,程序有错误啊
- wales2012-12-13修改了下,省事儿多了
- bcw522013-02-21的确用不了。怎么修改呀
- aaa22222014-08-19有参考价值
小小的蚂蚁
- 粉丝: 9
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功