參考自 這裡
View:
在 Ext.grid.GridPanel 上面添加 item 讓用戶可以動態選擇 Page Size: (demo)
Code:
View:
在 Ext.grid.GridPanel 上面添加 item 讓用戶可以動態選擇 Page Size: (demo)
Code:
- Ext.onReady(function(){
- Ext.BLANK_IMAGE_URL = '../js/ext-3.4.0/resources/images/default/s.gif';
- Ext.QuickTips.init();
- Ext.form.Field.prototype.msgTarget = 'qtip';//統一指定錯誤訊息提示方式
- var limit = 5;
- var combo = new Ext.form.ComboBox({
- name : 'perpage',
- width: 40,
- store: new Ext.data.ArrayStore({
- fields: ['id'],
- data : [
- [limit],
- ['10'],
- ['15']
- ]
- }),
- mode : 'local',
- value: limit,
- listWidth : 40,
- triggerAction : 'all',
- displayField : 'id',
- valueField : 'id',
- editable : false,
- forceSelection: true
- });
- combo.on('select', function(combo, record) {
- pageBar.pageSize = parseInt(record.get('id'), 10);
- pageBar.cursor = 0;
- store.load({params:{start: pageBar.cursor, limit: pageBar.pageSize}});
- }, this);
- var store = new Ext.data.Store({//配置分組數據集
- autoLoad :{params : {start : 0,limit : limit}},
- reader: new Ext.data.JsonReader(),
- proxy : new Ext.data.HttpProxy({
- url : 'jsonServer.jsp'
- })
- });
- var pageBar = new Ext.PagingToolbar({//分頁工具欄
- store : store,
- pageSize : limit,
- displayInfo : true,
- displayMsg : '第 {0} 條到 {1} 條,一共 {2} 條',
- emptyMsg : "沒有數據",
- items : [
- '-',
- 'Per Page: ',
- combo
- ]
- });
- var grid2 = new Ext.grid.GridPanel({
- id : 'myGridID2',
- title : '表格數據分頁',
- viewConfig: {forceFit: true},
- width:800,
- height:500,
- frame:true,
- renderTo: null,
- tbar : pageBar,
- store: store,
- columns: [//配置表格列
- new Ext.grid.RowNumberer(),//表格行號組件
- {header: "id", width: 80, dataIndex: 'personId', sortable: true},
- {header: "姓名", width: 100, dataIndex: 'personName', sortable: true},
- {header: "年齡", width: 100, dataIndex: 'personAge', sortable: true}
- ]
- });
- var win = new Ext.Window({
- title: 'Index',
- closable: false,
- height:600,
- width: 650,
- bodyStyle: 'padding:10px',
- contentEl: 'content',
- autoScroll: true,
- collapsible: true,
- draggable: true,
- maximizable: true,
- items: [grid2]
- });
- win.show();
- });
This message was edited 1 time. Last update was at 29/01/2013 17:49:32
沒有留言:
張貼留言