Rajat Sharma
1 Dec 2011, 8:41 PM
Hi.
Upon click of a hyperlink, a grid gets created on the screen and loads data from server. Since it is one of my basic examples, i put everything in Ext.onReady.
Ext.onReady(function() {
var getUserList = function(){
var userStore = Ext.create('Ext.data.Store', {
model: 'User',
pageSize: 15,
proxy: {
type: 'ajax',
url : 'ActionServlet?task=userList',
reader: {
type: 'json',
model: 'User',
totalProperty : 'total',
successProperty: 'success',
root: 'data'
}
}
});
Ext.create('Ext.grid.Panel', {
renderTo: Ext.getBody(),
store: userStore,
width: 400,
height: 400,
title: 'Users',
columns: [
{
text: 'Name',
width: 100,
sortable: true,
hideable: false,
dataIndex: 'name'
}
],
dockedItems: [{
xtype: 'pagingtoolbar',
store: userStore, // same store GridPanel is using
dock: 'bottom',
displayInfo: true
}]
});
userStore.load({
params: {
// specify params for the first page load if using paging
start: 0,
limit: 15
}
});
};
//var myDiv = Ext.get('main');
Ext.get('userLink').on('click', getUserList);
});
This works perfectly fine. After that I took the getUserList function out of onReady. i,e:
var getUserList = function(){
// entire grid creation and loading.
}
Ext.onReady(function() { Ext.get('userLink').on('click', getUserList);
});
Now upon click of the very same hyperlink, there are two grids created, vertically. I am not conceptually clear with Ext js. Is there anything I need to know w.r.t onReady function. Why 2 grids ?
Upon click of a hyperlink, a grid gets created on the screen and loads data from server. Since it is one of my basic examples, i put everything in Ext.onReady.
Ext.onReady(function() {
var getUserList = function(){
var userStore = Ext.create('Ext.data.Store', {
model: 'User',
pageSize: 15,
proxy: {
type: 'ajax',
url : 'ActionServlet?task=userList',
reader: {
type: 'json',
model: 'User',
totalProperty : 'total',
successProperty: 'success',
root: 'data'
}
}
});
Ext.create('Ext.grid.Panel', {
renderTo: Ext.getBody(),
store: userStore,
width: 400,
height: 400,
title: 'Users',
columns: [
{
text: 'Name',
width: 100,
sortable: true,
hideable: false,
dataIndex: 'name'
}
],
dockedItems: [{
xtype: 'pagingtoolbar',
store: userStore, // same store GridPanel is using
dock: 'bottom',
displayInfo: true
}]
});
userStore.load({
params: {
// specify params for the first page load if using paging
start: 0,
limit: 15
}
});
};
//var myDiv = Ext.get('main');
Ext.get('userLink').on('click', getUserList);
});
This works perfectly fine. After that I took the getUserList function out of onReady. i,e:
var getUserList = function(){
// entire grid creation and loading.
}
Ext.onReady(function() { Ext.get('userLink').on('click', getUserList);
});
Now upon click of the very same hyperlink, there are two grids created, vertically. I am not conceptually clear with Ext js. Is there anything I need to know w.r.t onReady function. Why 2 grids ?