View Full Version : EditorGrid + ComboBox + getPosition bug

1 Feb 2011, 11:53 PM
I'm pretty new to Ext, so it's possible I'm doing something stupid...
But I seem to be experiencing a bug with getPostion for ComboBox when used as an editor for a grid column.

It will sometimes return a meaningful value, and sometimes return negative junk.
From what I can tell, the ComboBox editor object actually attaches to an input box, *not* the div that's visible when not editing the cell.

When you aren't editing the field in question, the actual DOM element it's associated to appears to be hidden ( and vice versa when not editing ) so presumably it's unable to determine the position, and returns negative garbage.

Sometimes it will return the correct value on a change event, for instance, but it seems to be a race condition between the change event firing and the (de)rendering of the editor inputbox. If you ask the ComboBox object for it's position when not editing the cell, it fails every time. Reciprocally, it works every time when the cell is actively being edited.

It would seem to me that getPosition should return the position of the input field OR the display div, depending on which one knows it's position at that moment.

Pseudocode to repro:

var cbox = new Ext.form.ComboBox({
store: mycombostore,
listeners: {
'change': function(combo){
var xy = combo.getPosition();
HERE - trying to use xy to position a menu below
but _sometimes_ xy is a garbage value. something like: [-9993,-9931]

var grid = new Ext.grid.EditorGridPanel({
store: mystore,
columns: [
{header: 'NaughtyBox', width: 100, dataIndex: 'whatever', editor: cbox }

Admittedly, I know very little about the internals at this point. Am I missing something here?

2 Feb 2011, 1:32 AM
I don't agree.

The combobox is used as the field of a GridEditor and the grid editor is aligned to the cell when editing and moved offscreen when not in use.

1. Why are you event using the change event? I would recommend using the editorgrid afteredit event instead.
2. The afteredit event passes the current row and column which you can use to get the current cell from the gridview.

listeners: {
afteredit: function(e) {
if (e.field == 'whatever') {
var cell = e.grid.getView().getCell(e.row, e.column);
var pos = Ext.fly(cell).getXY();

2 Feb 2011, 5:25 PM
Ahh... that seems like a worthy way to look at it. I guess I had erroneously seen the editor as being the logical manifestation of the cell itself... Didn't realize that it was a free-agent.

Thus far, my experience with Ext has been overwhelmingly positive, but the docs leave a little to be desired, and there's a lot to sift through out there.

Anyhow, the point of this is that I'm trying to use the ComboBox editor to find / enter a value that must match a pre-existing record in the database... else I'm trying to position a panel, docked right below it, so as to prompt the user to create a new record.

Thanks :-)