Results 1 to 7 of 7

Thread: ExtJS 6.0.2 Ext.grid.locking.HeaderContainer applyColumnsState error

    Wait! Looks like we don't have enough information to add this to bug database. Please follow this template bug format.
  1. #1
    Sencha Premium User
    Join Date
    Apr 2016
    Posts
    9

    Default ExtJS 6.0.2 Ext.grid.locking.HeaderContainer applyColumnsState error

    I have a grid with stateful and locked columns. If new columns get added to the grid that weren't in previously stored state, getting: TypeError: Cannot read property 'index' of undefined at Ext.define.applyColumnsState

    Your code here is just assuming colState is defined/not null. The code above in this function was done correctly but you all made a bad assumption here. Please fix for 6.0.3

    Code:
        for (i = 0; i < length; i++) {
            column = columns[i];
            colState = columnsState[column.getStateId()];
            if (!column.locked) {
                colState.index -= lockedCount;
            }
        }
    Last edited by mmayer; 21 Apr 2016 at 5:32 PM. Reason: format code

  2. #2
    Sencha User
    Join Date
    Feb 2013
    Location
    California
    Posts
    11,985

    Default

    Thanks for the report. Can you please post a test case which reproduces this issue?
    https://fiddle.sencha.com/#home

  3. #3
    Sencha Premium User
    Join Date
    Apr 2016
    Posts
    9

    Default

    I don't have time to build that up. I'll give you the override that fixes it. It's just a check for not null - same thing you all did in the first for loop of this method.

    i suspect if you create a grid with 3 columns and stateful, then destroy it. then create a new grid with the same stateId but adding a 4th column you'd hit this case.

    Code:
    /**
     * Overrides for Ext.grid.locking.HeaderContainer
     * @author mmayer
     */
    Ext.define('Innotas.overrides.ext.grid.locking.HeaderContainer', {
        override: 'Ext.grid.locking.HeaderContainer',
    
    
        // Fix for this: https://www.sencha.com/forum/showthread.php?310451-ExtJS-6.0.2-Ext.grid.locking.HeaderContainer-applyColumnsState-error&p=1133558#post1133558
        // go to timesheet and toggle show days on/off to reproduce
    
    applyColumnsState: function (columnsState, storeState) {
            var me             = this,
                lockedGrid     = me.lockable.lockedGrid,
                lockedHeaderCt = lockedGrid.headerCt,
                normalHeaderCt = me.lockable.normalGrid.headerCt,
                columns        = lockedHeaderCt.items.items.concat(normalHeaderCt.items.items),
                length         = columns.length,
                i, column,
                switchSides,
                colState,
                lockedCount;
    
            // Loop through the column set, applying state from the columnsState object.
            // Columns which have their "locked" property changed must be added to the appropriate
            // headerCt.
    for (i = 0; i < length; i++) {
                column = columns[i];
                colState = columnsState[column.getStateId()];
                if (colState) {
    
                    // See if the state being applied needs to cause column movement
                    // Coerce possibly absent locked config to boolean.
    switchSides = colState.locked != null && Boolean(column.locked) !== colState.locked;
    
                    if (column.applyColumnState) {
                        column.applyColumnState(colState, storeState);
                    }
    
                    // If the column state means it has to change sides
                    // move the column to the other side
    if (switchSides) {
                        (column.locked ? lockedHeaderCt : normalHeaderCt).add(column);
                    }
                }
            }
            lockedCount = lockedHeaderCt.items.items.length;
    
            // We must now restore state in each side's HeaderContainer.
            // This means passing the state down into each side's applyColumnState
            // to get sortable, hidden and width states restored.
            // We must ensure that the index on the normal side is zero based.
    for (i = 0; i < length; i++) {
                column = columns[i];
                colState = columnsState[column.getStateId()];
                //FIX: mmayer fixed this line here (add check for colState)
    if (colState && !column.locked) {
                    colState.index -= lockedCount;
                }
            }
    
            // Each side must apply individual column's state
    lockedHeaderCt.applyColumnsState(columnsState, storeState);
            normalHeaderCt.applyColumnsState(columnsState, storeState);
        }
    
    });

  4. #4
    Sencha User
    Join Date
    Mar 2011
    Location
    Arvada, CO
    Posts
    404

    Default

    There's a test case in my thread... think it revolves around the same issue.


  5. #5
    Sencha User
    Join Date
    Feb 2013
    Location
    California
    Posts
    11,985

    Default

    Thanks for the report. I see the behavior in 6.0.2 but it seems to be fixed using a recent nightly. Are you able to confirm the same using a 6.0.3 nightly?

  6. #6
    Sencha Premium User
    Join Date
    Apr 2016
    Posts
    9

    Default

    6.1 nightly seems fixed. 6.0 nightly does not.

  7. #7
    Ext JS Premium Member
    Join Date
    Aug 2010
    Posts
    66

    Default

    Today I had a requirement that resulted in hitting this same issue (users want a button on a grid to clear stored state and immediately reflect the default configuration). As of 6.2.0, I still see the warnings when I implement this feature. Here's my simple example:

    Code:
    Ext.state.Manager.setProvider(new Ext.state.CookieProvider({
      expires : new Date(new Date().getTime() + (1000 * 60 * 60 * 24 * 7)),
    }));
    
    
    Ext.define("Record", {
      extend : "Ext.data.Model",
      fields : [
        "field1", "field2", "field3", "field4"
      ]
    });
    var myStore = Ext.create( "Ext.data.Store", { model : "Record", data : [ ] } );
    
    
    function addRows(inHowMany) {
      var a  = [ ];
      for (var i = 0; i < inHowMany; i++) {
        var r = { };
        for (var j = 1; j < 5; j++) {
          var f = "field" + j;
          r[f] = Math.floor(Math.random() * 899) + 100;
        }
        a.push(new Record(r));
      }
      myStore.loadData(a, true);
    }
    
    
    addRows(10);
    
    
    Ext.onReady(function() {
    
    
      new Ext.Viewport({
        items : [
          { xtype : "grid", store : myStore, stripeRows : true, stateful : true,
            width : 500, height : 300, title : "Test", stateId : "myGrid",
            id : "myGrid",
            columns : [
              { text : "field1", id : "col1", dataIndex : "field1", width : 100 },
              { text : "field2", id : "col2", dataIndex : "field2", width : 100 },
              { text : "field3", id : "col3", dataIndex : "field3", width : 100 },
              { text : "field4", id : "col4", dataIndex : "field4", width : 100 }
            ],
            buttons : [
              { text : "Do It", handler : function() {
                  var grid = this.up("grid");
                  Ext.state.Manager.clear(grid.stateId);
                  grid.reconfigure(grid.getStore(), grid.initialConfig.columns);
                }
              }
            ]
          }
        ]
      });
    
    
    });
    I didn't play with the suggested override only because the discussion here seems to indicate this was already resolved and so I should NOT be seeing these warnings in 6.2.0. Can anyone on the Sencha side confirm if this is still an active bug and/or what version definitively has or will have a fix?

    Thanks,
    Frank

Similar Threads

  1. Grid HeaderContainer border in 4.2.x
    By Jangla in forum Ext: Q&A
    Replies: 9
    Last Post: 22 Apr 2015, 12:59 AM
  2. Replies: 4
    Last Post: 6 Jun 2014, 8:27 PM
  3. [FIXED] 4.2 Error with locking tree grid
    By mankz in forum Ext:Bugs
    Replies: 3
    Last Post: 17 May 2013, 9:56 AM
  4. Replies: 1
    Last Post: 29 Mar 2012, 3:09 AM
  5. Replies: 0
    Last Post: 24 Aug 2011, 3:50 AM

Tags for this Thread

Posting Permissions

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