Results 1 to 6 of 6

Thread: Operator precedence bug in Ext.grid.plugin.Editing#onCellClick

    Success! Looks like we've fixed this one. According to our records the fix was applied for EXTJS-23269 in 6.2.2.
  1. #1
    Sencha Premium Member
    Join Date
    Aug 2012
    Posts
    30

    Default Operator precedence bug in Ext.grid.plugin.Editing#onCellClick

    This seems to be an issue in 6.2.0, but I don't recall running into it on 6.0.1


    Code:
    Ext.define('Ext.grid.plugin.Editing', {
        ...
        onCellClick: function(view, cell, colIdx, record, row, rowIdx, e) {
            // Used if we are triggered by a cellclick event
            // *IMPORTANT* Due to V4.0.0 history, the colIdx here is the index within ALL columns, including hidden.
            //
            // Make sure that the column has an editor.  In the case of CheckboxModel,
            // calling startEdit doesn't make sense when the checkbox is clicked.
            // Also, cancel editing if the element that was clicked was a tree expander.
            var ownerGrid = view.ownerGrid,
                expanderSelector = view.expanderSelector,
                // Use getColumnManager() in this context because colIdx includes hidden columns.
                columnHeader = view.ownerCt.getColumnManager().getHeaderAtIndex(colIdx),
                editor = columnHeader.getEditor(record),
                targetCmp;
            if (this.shouldStartEdit(editor) && (!expanderSelector || !e.getTarget(expanderSelector))) {
                ownerGrid.setActionableMode(true, e.position);
            }
            // Clicking on a component in a widget column
            else if (ownerGrid.actionableMode && view.owns(e.target) && (targetCmp = Ext.Component.fromElement(e.target, cell) && targetCmp.focusable)) {
                return;
            }
            // The cell is not actionable, we we must exit actionable mode
            else if (ownerGrid.actionableMode) {
                ownerGrid.setActionableMode(false);
            }
        },
    The error message is:

    VM38703:1 Uncaught TypeError: Cannot read property 'focusable' of undefined(…)

    The problem occurs where it tries to figure out if clicking a component in a widget column. The assignment of targetCmp happens after the check of targetCmp.focusable because && operator has precedence over assignment operator.

    The call to Ext.Component.fromElement(e.target, cell) returns a value, but the && is evaluated before it's actually assigned to the targetCmp variable so targetCmp is still undefined when it tries to access the 'focusable' variable.

    I think there's a missing set of parentheses around the assignment here:

    Code:
    else if (ownerGrid.actionableMode && view.owns(e.target) && (targetCmp = Ext.Component.fromElement(e.target, cell) && targetCmp.focusable))
    Should be:

    Code:
    else if (ownerGrid.actionableMode && view.owns(e.target) && ((targetCmp = Ext.Component.fromElement(e.target, cell)) && targetCmp.focusable))

  2. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,240

    Default

    Can you post a test case where you can reproduce the issue? Do you see the same thing with Ext 6.2.1?

    I seem to recall there were some changes in 6.2.1 to handle moving to a widget at a level higher than editing, so perhaps that piece of code is redundant now.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  3. #3
    Sencha Premium Member
    Join Date
    Aug 2012
    Posts
    30

    Default

    I upgraded to 6.2.1 and it's still broken. This is probably not exactly what you wanted, but here's a fiddle that proves the code can't possibly work:

    https://fiddle.sencha.com/#view/editor&fiddle/1m6c

    Thanks

  4. #4
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,240

    Default

    Yeah I understand what you're saying, just curious about how you managed to hit it. I was trying to reproduce it by starting an edit on a column, then clicking over to a widget column with a button, but onCellClick never fired there, something like:

    Code:
    Ext.onReady(function() {
        new Ext.grid.Panel({
            width: 400,
            height: 400,
            renderTo: document.body,
            store: {
                fields: ['name'],
                data: [{
                    name: 'Foo'
                }, {
                    name: 'Bar'
                }]
            },
            plugins: [{
                ptype: 'cellediting'
            }],
            columns: [{
                dataIndex: 'name',
                field: 'textfield'
            }, {
                xtype: 'widgetcolumn',
                dataIndex: 'name',
                widget: {
                    xtype: 'button'
                }
            }]
        });
    });
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  5. #5
    Sencha Premium Member
    Join Date
    Aug 2012
    Posts
    30

    Default

    I updated the fiddle with a test case that reproduces it. I think all you were missing is 'clicksToEdit: 1' on the plugin config.

    https://fiddle.sencha.com/#view/editor&fiddle/1m6c

  6. #6
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,240

    Default

    Ah, right you are. Thanks.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

Similar Threads

  1. Replies: 2
    Last Post: 14 Oct 2013, 1:56 PM
  2. Bug in Ext.grid.plugin.Editing ?
    By miroperez in forum Ext: Q&A
    Replies: 5
    Last Post: 30 Sep 2013, 10:27 AM
  3. Grid + Editing plugin - lastEdit
    By Zdeno in forum Ext: Q&A
    Replies: 2
    Last Post: 4 Jan 2013, 3:07 PM
  4. Replies: 2
    Last Post: 11 Sep 2012, 5:37 AM
  5. grid raw editing plugin
    By sharifr2002 in forum Ext:User Extensions and Plugins
    Replies: 0
    Last Post: 3 Jul 2011, 12:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •