Code:
Ext.onReady(function(){
Ext.define('model', {
extend: 'Ext.data.Model',
idProperty: 'abbr',
fields: [
{ name: 'abbr' },
{ name: 'name' },
{ name: 'slogan' }
],
proxy: {
type: 'ajax',
actionMethods: 'POST',
url: 'server.php',
reader: {
type: 'json',
root: 'data',
totalProperty: 'total'
},
afterRequest: function(request,success){
console.log(request);
console.log(success);
}
}
});
var store = Ext.create('Ext.data.Store', {
autoLoad: true, // also tested false using button to load
type: 'json',
model: 'model',
pageSize: 35,
remoteSort: true,
sorters: [
{
property : 'abbr',
direction: 'ASC'
}
],
listeners: {
beforeload: function(){
var searchValue = toolbar.down('#search-field').value;
store.getProxy().extraParams = {}; // clear all previous
store.getProxy().extraParams.search = searchValue; // update persistent param
}
}
});
var toolbar = Ext.create('widget.toolbar', {
dock: 'top',
ui: 'default',
items: ['Search',
{
xtype: 'textfield',
itemId: 'search-field',
name: 'searchField',
hideLabel: true,
width: 200
},
{
xtype: 'button',
text: '<<< search value',
handler: function(){
store.load(
{
params : {
start: 0,
limit: 35,
sort: '[{"property":"abbr","direction":"ASC"}]'
},
callback: function(records,operation,success){
// inspect: operation.resultSet.message (object)
// inspect: operation.response.responseText (json)
}
});
}
}
]
});
var grid = Ext.create('Ext.grid.Panel', {
store: store,
columns: [
{
text : 'State',
width : 75,
sortable : true,
dataIndex: 'abbr'
},
{
text : 'Name',
width : 175,
sortable : true,
dataIndex: 'name'
},
{
text : 'Slogan',
flex : 1,
sortable : true,
dataIndex: 'slogan'
},
],
height: 650, // remove for variable height
width: 600,
title: 'JSON Grid',
renderTo: Ext.getBody(),
viewConfig: {
loadingHeight: 150,
loadingText: 'This is a loading text message ...'
},
dockedItems: [
toolbar
],
bbar: Ext.create('Ext.PagingToolbar', {
store: store,
itemId: 'paging-toolbar',
displayInfo: true,
displayMsg: 'Displaying {0} - {1} of {2}',
emptyMsg: 'No records to display'
})
});
var button = new Ext.Button({
text: 'load store',
width: 150,
renderTo: Ext.getBody(),
handler: function(){
store.load();
}
});
var searchField = toolbar.down('#search-field');
searchField.focus();
});
Regards,