extjs的分頁感悟
Extjs中分頁的使用:
在后臺查詢程序中查詢出的數據集合要放在一個輔助類的對象中輔助類要有2個屬性,一個放數據總數,一個房數據集合,例如:
public class DirectStore {
private int totalRecords;
private final List<?> results;
public DirectStore(final int totalRecord, final List<?> results) {
super();
this.totalRecords = totalRecord;
this.results = results;
}
public List<?> getResults() {
return this.results;
}
public int getTotalRecord() {
return this.totalRecords;
}
public void setTotalRecord(final int totalRecord) {
this.totalRecords = totalRecord;
}
@Override
public String toString() {
return "{'totalRecords':" + this.totalRecords + ",'results'"
+ this.results + "}";
}
}
把查詢出的額數據集合放在對象中
DirectStore store = new DirectStore(recordNumber, list);
在ext的頁面中,需要先定義如下:
var typeStore = new Ext.data.DirectStore({
paramOrder : [ 'start', 'limit' ],
baseParams : {
'start' : 0,
'limit' : 20
},
root : 'results',
totalProperty : 'totalRecords',//和DirectStore對象的totalRecords屬性一樣
idProperty : 'id',
fields : [ 'id', 'name', 'Unit', 'description' ],//集合中存放的對象的屬性
directFn : EamDjn.getDepartment
});
typeStore.load();
再在頁面下面寫:
bbar: new Ext.PagingToolbar({
pageSize: 20,
store : typeStore,
displayInfo: true,
displayMsg: '顯示第 {0} 條到 {1} 條記錄,一共 {2} 條',
emptyMsg: '沒有記錄'
})
這樣就完成分頁了,需要