Grid definition:
Code:
Ext.define('myGrid', {
extend: 'Ext.panel.Panel',
alias: 'widget.mygrid',
layout: {
type: 'border'
},
requires: [
'Ext.grid.*',
'Ext.data.*',
'Ext.toolbar.Paging',
'Ext.ux.grid.FiltersFeature'
],
defaults: {
split: true
},
initComponent: function() {
Ext.log({
msg: Ext.getClassName(this) + '.initComponent: ' + 'start',
level: 'info',
stack: false
});
this.items = [{
xtype: 'gridpanel',
itemId: 'grdSearchResult',
region: 'center',
forceFit: false,
selType: 'cellmodel',
columns: [{
xtype: 'gridcolumn',
itemId: 'colNameSpace',
text: 'Name Space',
sortable: true,
hideable: false,
menuDisabled: false,
draggable: true,
groupable: false,
dataIndex: 'name_space',
minWidth: 100,
filter: {
type: 'string'
},
editor: {
xtype: 'textfield',
readOnly : true
}
}],
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 2
})
],
features: [{
ftype: 'filters',
encode: false, // json encode the filter query
local: true // defaults to false (remote filtering)
}],
dockedItems: [{
xtype: 'pagingtoolbar',
itemId: 'tbrPaging',
dock: 'bottom',
displayInfo: true,
displayMsg: 'Displaying {0} - {1} of {2}',
emptyMsg : 'No data to display',
items: [
'-',
{
xtype: 'numberfield',
itemId: 'nbfPageSize',
fieldLabel: 'Records Per Page',
labelAlign: 'right',
value: 20,
size: 5,
minValue: 1,
allowDecimals: false
},
'-',
{
xtype: 'button',
itemId: 'btnClearFilter',
text: 'Clear All Filters'
}]
}],
viewConfig: {
}
}];
this.callParent(arguments);
}
});
My controller definition:
Code:
Ext.define('myController', {
extend: 'Ext.app.Controller',
init: function() {
var me = this;
this.control({
'.mygrid > #grdSearchResult > #tbrPaging > #nbfPageSize': {
'change': {fn: this.setPageSize, scope: this, single: false}
},
'.mygrid > #grdSearchResult > #tbrPaging > #btnClearFilter': {
'click': {fn: this.clearFilter, scope: this, single: false}
}
});
},
doSearch: function(grdResult) {
var me = this;
var tbrPaging = grdResult.child('#tbrPaging');
var nbfPageSize = tbrPaging.child('#nbfPageSize');
var arrayTable = new Array();
//get all data in arrayTable
var pagingStore = grdResult.getStore();
if (pagingStore) pagingStore.removeAll(false);
pagingStore = Ext.create('myStore');
grdResult.reconfigure(pagingStore);
tbrPaging.bindStore(pagingStore);
pagingStore.getProxy().data = arrayTable;
pagingStore.pageSize = nbfPageSize.getValue();
pagingStore.load();
},
setPageSize: function(fieldThis, newValue, oldValue, eOpts) {
var grdSearchResult = fieldThis.up('#tbrPaging').up('#grdSearchResult');
var store = grdSearchResult.getStore();
if (store) store.pageSize = fieldThis.getValue();
},
clearFilter: function(fieldThis, event, eOpts) {
var grdSearchResult = fieldThis.up('#tbrPaging').up('#grdSearchResult');
grdSearchResult.filters.clearFilters();
}
});
The store:
Code:
Ext.define('myStore', {
extend: 'Ext.data.Store',
model: 'myModel',
requires: [
'Ext.ux.data.PagingMemoryProxy'
],
autoLoad: false,
pageSize: 20,
proxy: {
type: 'pagingmemory',
reader: {
type: 'json'
}
}
});
The Model:
Code:
Ext.define('myModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'name_space', type: 'string'}
]
});