Bobafart
19 May 2007, 9:09 AM
I have successfully created an editable grid where, if you click a specific column, a Layout Dialog pops up and async loads data based on the item clicked.
It works for the first click.
The problem is, it only works for the first click. The second, third and all future clicks still load the Layout Dialog but the data from the first click remains displayed -- the future clicks don't refresh the data.
I am clearly doing something wrong .. but I am not sure what. No errors are outputted.
<script type="text/javascript">
Ext.onReady(function(){
// create the Data Store
var ds = new Ext.data.Store({
// load using HTTP
proxy: new Ext.data.HttpProxy({url: 'php/armyExt.php'}),
// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
// records will have an "Item" tag
record: 'item',
id: 'troopId'
}, [
// set up the fields mapping into the xml doc
// The first needs mapping, the others are very basic
{name: 'troopId', mapping: 'itemAttribute > troopID'},
'troopName', 'troopHP', 'troopSquad', 'troopSpecialty', 'troopRank', 'troopCustomize'
])
});
var cm = new Ext.grid.ColumnModel([
{header: "SoldierID", hidden: true, dataIndex: 'troopId'},
{header: "Soldier", width: 120, dataIndex: 'troopName'},
{header: "HP", width: 60, dataIndex: 'troopHP'},
{header: "Squad",
width: 80,
dataIndex: 'troopSquad',
editor: new Ext.grid.GridEditor(new Ext.form.ComboBox({
typeAhead: true,
editable: false,
triggerAction: 'all',
transform:'troopSquad',
lazyRender:true
}))
},
{header: "Specialty", width: 100, dataIndex: 'troopSpecialty'},
{header: "Rank", width: 100, dataIndex: 'troopRank'},
{header: "Customize", width: 60, dataIndex: 'troopCustomize'}
]);
cm.defaultSortable = true;
// create the grid
var grid = new Ext.grid.EditorGrid('armyGrid', {
ds: ds,
cm: cm,
selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
enableColLock:false,
loadMask: true
});
grid.render();
ds.load();
// open the Unit Detailed Information Dialog if Activated
var dialog;
function openDialog(grid, rowIndex, colIndex, e) {
var selectionModel = grid.getSelectionModel();
var record = selectionModel.getSelected();
var troopId = record.data['troopId'];
var troopName = record.data['troopName'];
// alert(troopId, troopName);
if(colIndex==6){
alert('you clicked unit id: '+troopId);
if(!dialog){ // lazy initialize the dialog and only create it once
dialog = new Ext.LayoutDialog("soldierDetails", {
modal:true,
width:600,
height:400,
shadow:true,
minWidth:300,
minHeight:300,
proxyDrag: true,
west: {
split:true,
initialSize: 150,
minSize: 100,
maxSize: 250,
titlebar: true,
collapsible: true,
animate: true
},
center: {
autoScroll:true,
tabPosition: 'top',
closeOnTab: true,
alwaysShowTabs: true
}
});
dialog.addKeyListener(27, dialog.hide, dialog);
dialog.addButton('Submit', dialog.hide, dialog);
dialog.addButton('Close', dialog.hide, dialog);
var layout = dialog.getLayout();
var dialogCenter = Ext.get('center');
dialogCenter.load({
url: "php/detailedInfo.php",
params: {id: troopId}, // or a URL encoded string
// callback: yourFunction,
// scope: yourObject, //(optional scope)
discardUrl: false,
nocache: false,
text: "Loading...",
timeout: 30
// scripts: false
});
layout.beginUpdate();
layout.add('west', new Ext.ContentPanel('west', {title: 'Inventory'}));
layout.add('center', new Ext.ContentPanel('center', {title: 'Unit Profile'}));
// generate some other tabs
layout.add('center', new Ext.ContentPanel('statistics', {
autoCreate:true, title: 'Unit Statistics', background:true}));
layout.add('center', new Ext.ContentPanel('skills', {
autoCreate:true, title: 'Unit Skills', closable:true, background:true}));
layout.endUpdate();
}
dialog.show();
}
}
grid.addListener('cellclick', openDialog, this);
});
</script>
Here is a live demo (click on the "Customize" column for the layout dialog to appear):
http://gabbr.com/c/departmentofdefense/army/indexExt5.php
Any help would be greatly appreciated.
It works for the first click.
The problem is, it only works for the first click. The second, third and all future clicks still load the Layout Dialog but the data from the first click remains displayed -- the future clicks don't refresh the data.
I am clearly doing something wrong .. but I am not sure what. No errors are outputted.
<script type="text/javascript">
Ext.onReady(function(){
// create the Data Store
var ds = new Ext.data.Store({
// load using HTTP
proxy: new Ext.data.HttpProxy({url: 'php/armyExt.php'}),
// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
// records will have an "Item" tag
record: 'item',
id: 'troopId'
}, [
// set up the fields mapping into the xml doc
// The first needs mapping, the others are very basic
{name: 'troopId', mapping: 'itemAttribute > troopID'},
'troopName', 'troopHP', 'troopSquad', 'troopSpecialty', 'troopRank', 'troopCustomize'
])
});
var cm = new Ext.grid.ColumnModel([
{header: "SoldierID", hidden: true, dataIndex: 'troopId'},
{header: "Soldier", width: 120, dataIndex: 'troopName'},
{header: "HP", width: 60, dataIndex: 'troopHP'},
{header: "Squad",
width: 80,
dataIndex: 'troopSquad',
editor: new Ext.grid.GridEditor(new Ext.form.ComboBox({
typeAhead: true,
editable: false,
triggerAction: 'all',
transform:'troopSquad',
lazyRender:true
}))
},
{header: "Specialty", width: 100, dataIndex: 'troopSpecialty'},
{header: "Rank", width: 100, dataIndex: 'troopRank'},
{header: "Customize", width: 60, dataIndex: 'troopCustomize'}
]);
cm.defaultSortable = true;
// create the grid
var grid = new Ext.grid.EditorGrid('armyGrid', {
ds: ds,
cm: cm,
selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
enableColLock:false,
loadMask: true
});
grid.render();
ds.load();
// open the Unit Detailed Information Dialog if Activated
var dialog;
function openDialog(grid, rowIndex, colIndex, e) {
var selectionModel = grid.getSelectionModel();
var record = selectionModel.getSelected();
var troopId = record.data['troopId'];
var troopName = record.data['troopName'];
// alert(troopId, troopName);
if(colIndex==6){
alert('you clicked unit id: '+troopId);
if(!dialog){ // lazy initialize the dialog and only create it once
dialog = new Ext.LayoutDialog("soldierDetails", {
modal:true,
width:600,
height:400,
shadow:true,
minWidth:300,
minHeight:300,
proxyDrag: true,
west: {
split:true,
initialSize: 150,
minSize: 100,
maxSize: 250,
titlebar: true,
collapsible: true,
animate: true
},
center: {
autoScroll:true,
tabPosition: 'top',
closeOnTab: true,
alwaysShowTabs: true
}
});
dialog.addKeyListener(27, dialog.hide, dialog);
dialog.addButton('Submit', dialog.hide, dialog);
dialog.addButton('Close', dialog.hide, dialog);
var layout = dialog.getLayout();
var dialogCenter = Ext.get('center');
dialogCenter.load({
url: "php/detailedInfo.php",
params: {id: troopId}, // or a URL encoded string
// callback: yourFunction,
// scope: yourObject, //(optional scope)
discardUrl: false,
nocache: false,
text: "Loading...",
timeout: 30
// scripts: false
});
layout.beginUpdate();
layout.add('west', new Ext.ContentPanel('west', {title: 'Inventory'}));
layout.add('center', new Ext.ContentPanel('center', {title: 'Unit Profile'}));
// generate some other tabs
layout.add('center', new Ext.ContentPanel('statistics', {
autoCreate:true, title: 'Unit Statistics', background:true}));
layout.add('center', new Ext.ContentPanel('skills', {
autoCreate:true, title: 'Unit Skills', closable:true, background:true}));
layout.endUpdate();
}
dialog.show();
}
}
grid.addListener('cellclick', openDialog, this);
});
</script>
Here is a live demo (click on the "Customize" column for the layout dialog to appear):
http://gabbr.com/c/departmentofdefense/army/indexExt5.php
Any help would be greatly appreciated.