PDA

View Full Version : [CLOSED]incorrect editor if two editor grids with same column model exists



jorgen.rasmussen
3 Jan 2011, 8:28 PM
Ext version tested:

Ext 3 rev 3
Adapter used:

ext
css used:

only default ext-all.css
Browser versions tested against:

IE7
Operating System:

WinXP Pro
Description:

I have a scenario where I dynamically instantiate editor grids in tabs for various data selections.
If two or more tabs are created using the same xtype, when a column is edited in one, it can't be edited in the other tabs.
I have simplified the problem down to a simple scenario with two grids on one page using the same xtype as a reference where the column model is defined.
If I instead pass the columns directly in each of the instantiations, it works. This however does not fit the requirement as the xtype is a reusable component.
Test Case:




<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- ExtJS library: -->
<linkrel="stylesheet"type="text/css"href="http://dev.sencha.com/deploy/dev/resources/css/ext-all.css"/>
<linkrel="stylesheet"type="text/css"href="http://dev.sencha.com/deploy/dev/examples/shared/examples.css"/>
<linkrel="stylesheet"type="text/css"href="grid-examples.css"/>
<scripttype="text/javascript"src="http://dev.sencha.com/deploy/dev/adapter/ext/ext-base.js"></script>
<scripttype="text/javascript"src="http://dev.sencha.com/deploy/dev/ext-all.js"></script>

<scriptlanguage="javascript">

gridPrototype = Ext.extend(Ext.grid.EditorGridPanel, {
height: 100,
width: 300,
store: new Ext.data.ArrayStore({
fields: [ 'company', 'price' ],
data: [
[ 'company 1', '10.25' ],
[ 'company 2', '12.50' ]
]
}),
columns: [
{
header : 'Company',
dataIndex: 'company',
editor: {xtype:'textfield'}
},{
header : 'Price',
dataIndex: 'price',
editor: {
xtype:'textfield',
listeners: {

}
}

}
]
});


Ext.onReady(function(){
var grid1 = new gridPrototype({renderTo:'grid1'});
var grid2 = new gridPrototype({renderTo:'grid2'})
}); // eo onReady
</script>

</head>
<body>
<divid="grid1"></div>
<divid="grid2"></div>
</body>
</html>






Steps to reproduce the problem:

click on one column in one of the grids
click on the same column in the other grid - the editor doesn't work (it may show up at the first grid)
The result that was expected:

Ability to instantiate multiple grids using an xtype without conflict (ie edit product a and product b at the same time)
The result that occurs instead:

the grid where you first click a column to edit is the only one that works, the other editor grid now doesn't show the editor
Debugging already done:

It appears that the editor is instatiated and creates a hidden div when first clicked. This is then used when clicked again. There is a conflict in how this is identified if there is more than one editor.
Possible fix:

Look into the scope of how the check for an existing editor div is done and ensure that there is no conflict if editor exist twice in an app.

evant
3 Jan 2011, 8:36 PM
Column models aren't supposed to be shared between grids, by putting in the prototype that's what you are doing. Instead, assign the column model during the initComponent method.

jorgen.rasmussen
3 Jan 2011, 8:52 PM
Thank you for your quick reply. I have moved it to the init component and it works but this means that I am unable to pass in a different column model to the xtype if needed. This is not in line with the general design pattern as I see it. I am unsure as of why a column model can't be defined in the prototype in the same way as a field list, listeners etc. I still believe that there is a scope problem in the code but will leave this to you for consideration.

mankz
3 Jan 2011, 10:54 PM
Jorgen, you can still pass in a column model to override the one set in initComponent by using Ext.applyIf.



initComponent : function() {

Ext.applyIf(this, {

columns : [...]
});
},

jorgen.rasmussen
3 Jan 2011, 11:09 PM
Hi Mankz,
Thank you for your reply. I agree that the syntax would allow me to pass it in but it will re-introduce the original bug wouldn't it?
Kind Regard
Jorgen

mankz
3 Jan 2011, 11:11 PM
Nope, you're still setting the property on the instance - not on the prototype. Should be fine! :)