ExtJs自定义分页组件

刚接触ExtJs的时候,由于用C#做Web项目,分页方法一般是传入当前页PageIndex和每页显示记录数PageSize获取数据,所以修改了ExtJs本身的PagingToolbar用于适应这种情况。贴出代码如下:

  1 ExpandedBlockStart.gif ContractedBlock.gif /**/ /**
  2* @author Terry
  3*/

  4
  5 ExpandedBlockStart.gifContractedBlock.gifExt.ux.PagingToolbar  =  Ext.extend(Ext.PagingToolbar,  {
  6    afterPageText: '/ {0}',
  7    beforePageText: '',
  8    displayInfo: true,
  9    displayMsg: '当前显示 {0} - {1}条记录 /共 {2}条记录',
 10    emptyMsg: '无显示数据',
 11    firstText: '第一页',
 12    prevText: '前一页',
 13    nextText: '后一页',
 14    lastText: '最后一页',
 15    refreshText: '刷新',
 16    pageSize: 50,
 17ExpandedSubBlockStart.gifContractedSubBlock.gif    paramNames: {
 18        start: 'pageIndex',
 19        limit: 'pageSize'
 20    }
,
 21
 22ExpandedSubBlockStart.gifContractedSubBlock.gif    updateInfo: function() {
 23ExpandedSubBlockStart.gifContractedSubBlock.gif        if (this.displayEl) {
 24            var count = this.store.getCount();
 25
 26            var msg = count == 0 ? this.emptyMsg : String.format(this.displayMsg, this.cursor, this.cursor + count - 1this.store.getTotalCount());
 27
 28            this.displayEl.update(msg);
 29        }

 30    }
,
 31
 32ExpandedSubBlockStart.gifContractedSubBlock.gif    onLoad: function(store, r, o) {
 33ExpandedSubBlockStart.gifContractedSubBlock.gif        if (!this.rendered) {
 34            this.dsLoaded = [store, r, o];
 35
 36            return;
 37        }

 38
 39ExpandedSubBlockStart.gifContractedSubBlock.gif        if (!o.params || this.store.getTotalCount() == 0{
 40            this.cursor = 0;
 41        }

 42ExpandedSubBlockStart.gifContractedSubBlock.gif        else {
 43            this.cursor = (o.params[this.paramNames.start] - 1* this.pageSize + 1;
 44        }

 45
 46        var d = this.getPageData(), ap = d.activePage, ps = d.pages;
 47
 48        this.afterTextEl.el.innerHTML = String.format(this.afterPageText, d.pages);
 49        this.field.dom.value = ap;
 50
 51        this.first.setDisabled(ap == 1 || ps == 0);
 52        this.prev.setDisabled(ap == 1 || ps == 0);
 53        this.next.setDisabled(ap == ps || ps == 0);
 54        this.last.setDisabled(ap == ps || ps == 0);
 55        this.loading.enable();
 56        this.loading.setDisabled(ps == 0);
 57        this.updateInfo();
 58    }
,
 59
 60ExpandedSubBlockStart.gifContractedSubBlock.gif    getPageData: function() {
 61        var total = this.store.getTotalCount();
 62
 63ExpandedSubBlockStart.gifContractedSubBlock.gif        return {
 64            total: total,
 65            activePage: total != 0 && this.cursor == 0 ? 1 : Math.ceil(this.cursor / this.pageSize),
 66            pages: total != 0 && total < this.pageSize ? 1 : Math.ceil(total / this.pageSize)
 67        }

 68    }
,
 69
 70ExpandedSubBlockStart.gifContractedSubBlock.gif    onClick: function(which) {
 71        var store = this.store;
 72        var d = this.getPageData();
 73
 74ExpandedSubBlockStart.gifContractedSubBlock.gif        switch (which) {
 75            case 'first':
 76                this.doLoad(1);
 77                break;
 78            case 'prev':
 79                this.doLoad(Math.max(1, d.activePage - 1));
 80                break;
 81            case 'next':
 82                this.doLoad(Math.min(d.pages, d.activePage + 1));
 83                break;
 84            case 'last':
 85                this.doLoad(d.pages);
 86                break;
 87            case 'refresh':
 88                this.doLoad(d.activePage);
 89                break;
 90        }

 91    }
,
 92
 93ExpandedSubBlockStart.gifContractedSubBlock.gif    onPagingKeydown: function(e) {
 94        var k = e.getKey(), d = this.getPageData(), pageNum;
 95
 96ExpandedSubBlockStart.gifContractedSubBlock.gif        if (k == e.RETURN) {
 97            e.stopEvent();
 98
 99            pageNum = this.readPage(d)
100
101ExpandedSubBlockStart.gifContractedSubBlock.gif            if (pageNum >= d.pages) {
102                pageNum = d.pages;
103            }

104ExpandedSubBlockStart.gifContractedSubBlock.gif            else if (pageNum <= 1{
105                pageNum = 1;
106            }

107
108            this.doLoad(pageNum);
109
110        }

111ExpandedSubBlockStart.gifContractedSubBlock.gif        else if (k == e.HOME || k == e.END) {
112            e.stopEvent();
113            pageNum = k == e.HOME ? 1 : d.pages;
114            this.field.dom.value = pageNum;
115        }

116ExpandedSubBlockStart.gifContractedSubBlock.gif        else if (k == e.UP || k == e.PAGEUP || k == e.DOWN || k == e.PAGEDOWN) {
117            e.stopEvent();
118
119ExpandedSubBlockStart.gifContractedSubBlock.gif            if (pageNum = this.readPage(d)) {
120                var increment = e.shiftKey ? 10 : 1;
121
122ExpandedSubBlockStart.gifContractedSubBlock.gif                if (k == e.DOWN || k == e.PAGEDOWN) {
123                    increment *= -1;
124                }

125
126                pageNum += increment;
127
128ExpandedSubBlockStart.gifContractedSubBlock.gif                if (pageNum >= 1 & pageNum <= d.pages) {
129                    this.field.dom.value = pageNum;
130                }

131            }

132        }

133    }

134}
);
135
136 Ext.reg( ' ux.pagingtoolbar ' , Ext.ux.PagingToolbar);

转载于:https://www.cnblogs.com/TerryLiang/archive/2009/03/22/1418882.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值