PDA

View Full Version : Locked Column CellIndex Distortion



@brady
16 Jul 2015, 2:21 PM
Sencha,


In 5.* and now 6.*, if you enable locking in the grid panel component, it can result in an incorrect cellIndex parameter being passed to cell* event listeners. Outlined below are the specific details of this defect. Note, I understand why this occurs. Per the API pages (http://docs.sencha.com/extjs/6.0/6.0.0-classic/#!/api/Ext.grid.Panel-event-lockcolumn), enabling lockable columns effectively splits the grid into two grids. The cell level event handlers are then describing their location in these grids. However, from the perspective of a view controller, its still one grid. Therefore, in my opinion, cellIndex should not describe a sub grid location. If an event handler is suppose to target locked (or unlocked) columns, then there should be corresponding lockedcellclick, unlockedcellclick events.


Thanks,


@brady



Stand Alone Test Case:

qkn


Ext Version tested:

Ext 6.0.0.640 (Classic)


Browser version tested against:

Chrome (ver 43.0.2357.134)


Description:

Outlined above. Create a grid with some locked columns and attach a cellclick, celldblclick or cellkeydown listener. The cellIndex parameters passed to the handlers for non-locked columns will always be off by the number of total locked columns.


Steps to Reproduce:

Define a class that extends the Ext.grid.Panel class

In the ViewConfig, set the “enableLockable” flag to true
Add two columns
On the first column set the “locked” flag to true
Add a cellclick event listener that writes the cellindex parameter value to the console

Compile / Run
Click the first column and then the second
The cellIndex for both events is zero
The result that was expected:

The cellIndex should be different based on the column you click. Clicking the first column should output 0. Clicking the second, should output 1.


The result that occurs instead:

The cellindex is always zero.


Workaround:

I ended up having to define a translation function (see below). This function is then used to adjust the value received by the event listener:



function getActualCellIndex(table, cellIndex) {
var view = this.getView(),
lockedTable = view.selModel.views[0],
offset = lockedTable.getColumnManager().getColumns().length;
if (table.id === lockedTable.id) {
return cellIndex;
} else {
return cellIndex + offset;
}
}

mitchellsimoens
28 Jul 2015, 9:30 AM
Thanks for the report! I have opened a bug in our bug tracker.

Animal
29 Aug 2015, 12:13 PM
I see what you mean that the column index reported is "local" to the view on either side.

But I don't think it actually matters.

The index is rarely what you actually need.

The Ext.grid.column.Column object is usually what is needed.

And 5.x upwards provides that.

https://docs.sencha.com/extjs/5.1/5.1.1-apidocs/#!/api/Ext.view.Table-event-beforecellclick

The events fired from Ext.view.Table contain a position property which is an https://docs.sencha.com/extjs/5.1/5.1.1-apidocs/#!/api/Ext.grid.CellContext

This uniquely identifies a cell based upon the Record/Ext.grid.column.Column intersection.

I think you can obtain all the contextual information that you need from that. Let me know if this provides a solution for you.