ExtJs自定义分页组件
刚接触ExtJs的时候,由于用C#做Web项目,分页方法一般是传入当前页PageIndex和每页显示记录数PageSize获取数据,所以修改了ExtJs本身的PagingToolbar用于适应这种情况。贴出代码如下:
1
/**
2
* @author Terry
3
*/
4![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
Ext.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,
17
paramNames: {
18
start: 'pageIndex',
19
limit: 'pageSize'
20
},
21![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
22
updateInfo: function() {
23
if (this.displayEl) {
24
var count = this.store.getCount();
25![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
26
var msg = count == 0 ? this.emptyMsg : String.format(this.displayMsg, this.cursor, this.cursor + count - 1, this.store.getTotalCount());
27![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
28
this.displayEl.update(msg);
29
}
30
},
31![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
32
onLoad: function(store, r, o) {
33
if (!this.rendered) {
34
this.dsLoaded = [store, r, o];
35![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
36
return;
37
}
38![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
39
if (!o.params || this.store.getTotalCount() == 0) {
40
this.cursor = 0;
41
}
42
else {
43
this.cursor = (o.params[this.paramNames.start] - 1) * this.pageSize + 1;
44
}
45![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
46
var d = this.getPageData(), ap = d.activePage, ps = d.pages;
47![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
48
this.afterTextEl.el.innerHTML = String.format(this.afterPageText, d.pages);
49
this.field.dom.value = ap;
50![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
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![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
60
getPageData: function() {
61
var total = this.store.getTotalCount();
62![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
63
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![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
70
onClick: function(which) {
71
var store = this.store;
72
var d = this.getPageData();
73![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
74
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![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
93
onPagingKeydown: function(e) {
94
var k = e.getKey(), d = this.getPageData(), pageNum;
95![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
96
if (k == e.RETURN) {
97
e.stopEvent();
98![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
99
pageNum = this.readPage(d)
100![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
101
if (pageNum >= d.pages) {
102
pageNum = d.pages;
103
}
104
else if (pageNum <= 1) {
105
pageNum = 1;
106
}
107![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
108
this.doLoad(pageNum);
109![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
110
}
111
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
}
116
else if (k == e.UP || k == e.PAGEUP || k == e.DOWN || k == e.PAGEDOWN) {
117
e.stopEvent();
118![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
119
if (pageNum = this.readPage(d)) {
120
var increment = e.shiftKey ? 10 : 1;
121![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
122
if (k == e.DOWN || k == e.PAGEDOWN) {
123
increment *= -1;
124
}
125![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
126
pageNum += increment;
127![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
128
if (pageNum >= 1 & pageNum <= d.pages) {
129
this.field.dom.value = pageNum;
130
}
131
}
132
}
133
}
134
});
135![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
136
Ext.reg('ux.pagingtoolbar', Ext.ux.PagingToolbar);
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
27
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
28
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
29
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
30
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
31
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
32
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
33
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
34
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
35
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
36
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
37
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
38
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
39
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
40
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
41
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
42
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
43
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
44
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
45
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
46
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
47
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
48
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
49
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
50
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
51
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
52
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
53
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
54
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
55
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
56
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
57
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
58
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
59
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
60
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
61
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
62
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
63
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
64
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
65
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
66
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
67
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
68
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
69
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
70
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
71
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
72
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
73
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
74
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
75
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
76
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
77
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
78
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
79
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
80
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
81
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
82
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
83
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
84
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
85
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
86
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
87
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
88
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
89
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
90
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
91
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
92
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
93
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
94
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
95
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
96
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
97
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
98
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
99
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
100
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
101
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
102
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
103
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
104
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
105
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
106
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
107
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
108
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
109
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
110
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
111
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
112
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
113
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
114
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
115
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
116
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
117
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
118
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
119
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
120
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
121
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
122
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
123
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
124
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
125
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
126
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
127
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
128
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
129
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
130
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
131
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
132
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
133
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
134
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
135
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
136
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)