PDA

View Full Version : Duplicate creation problem.



pirusira
27 May 2010, 2:24 AM
Hello All,

My app has menu and it changes items of a panel.
The panel has a GridPanel. The gridpanel gets data by run a struts2 action.
When the first time that I click the menu, but if I click the menu again, it doesn't show the panel any more like this
20672

This is supposed to look like this
20673

This is the event handler.


menuDevice.on('click', function(node){
if(node.isLeaf()){
if(node.id=='menuDevice-1'){
nestedCenter.removeAll();
nestedCenter.add(Menu_Device_DeviceList.getMenu_Device_DeviceList());
nestedCenter.doLayout();
}
}
});


This is the panel which is added by the event handler.


var store = new Ext.data.JsonStore({
url: 'mainDataCollector.action',
root: 'printerInfo',
idProperty: 'ip',
totalProperty: 'printerTotal',
fields: ['modelName', 'stateText', 'ip', 'groupName', 'printSum', 'statGetTime'],
remoteSort: true,
sortInfo: { field: "groupName", direction: "ASC" }
});
var myPageSize = 20;
var deviceListGrid = new Ext.grid.GridPanel({
border: false,
autoHeight:true,
autoWidth:true,
loadMask: true,
store: store,
columns: [
{header: "Model", dataIndex: 'modelName', width: 300, sortable: true},
{header: "Stat", dataIndex: 'stateText', width: 120, sortable: true},
{header: "IP", dataIndex: 'ip', width: 130, sortable: true/*, sortType:*/},
{header: "Group", dataIndex: 'groupName', width: 160, sortable: true},
{header: "TotalPrint", dataIndex: 'printSum', width: 120, sortable: true},
{header: "Update", dataIndex: 'statGetTime', width: 160, sortable: true}
]
});
store.load({ params: { start: 0, limit: myPageSize} });
Menu_Device_DeviceList = {
getMenu_Device_DeviceList: function() {
var Menu_Device_DeviceList = new Ext.Panel({
title: 'Device List',
autoScroll : true,
layout: 'fit',
items: deviceListGrid
});
return Menu_Device_DeviceList;
}
}


It doesn't show any error in firebug.
It just doesn't show the GridPanel after the first time.
I think it's problem about duplicate of loading the data.
Then, is there a way to remove the data when the method 'removeAll()' is called?
or other way to solve?
Any idea would help me.

Thanks in advance.
Stan

Condor
27 May 2010, 2:43 AM
No! Don't destroy the grid and create it again!

Instead, only reload the grid store.

pirusira
27 May 2010, 2:57 AM
How do I reload?
Add condition to compare whether it is the first time or not and if it's the firstime then load() and if it's not the firstime then reload()?
Then how can I compare it?
Let me know and show the example code please.
Thank you Condor.

CrazyEnigma
27 May 2010, 6:26 AM
When you called removeAll(), it destroyed the reference. So you can reload the grid by using the load() method. Within load, I believe there is a parameter that states to retain the existing records. Not too sure, you might need to check the API on this one.