Success! Looks like we've fixed this one. According to our records the fix was applied for EXTJSIV-6985 in 4.1.2.
  1. #1
    Ext JS Premium Member
    Join Date
    Nov 2010
    Location
    Rudolstadt, Germany
    Posts
    51
    Vote Rating
    0
    astuteq is on a distinguished road

      0  

    Default Dynamic grid column resizing

    Dynamic grid column resizing


    Hello,

    I try to resize grid columns at runtime.
    This is no problem with Ext 3, but it does not seem to work in Ext 4.
    There is no columnModel and nothing comparable...

    I have 2 grids. If the columns of grid one are resized, the columns of grid 2 must also be resized.


    This works with Ext 3:

    PHP Code:

    grid
    .on('columnresize', function (columnIndexnewSize){
                        
    //change the width of the column at the depending grid                    var sg = Ext.getCmp(Skm.SUMMARY_GRID);                    var cm = sg.getColumnModel();                    cm.setColumnWidth(columnIndex, newSize);                }); 
    Any Idea how I can do this in Ext 4?
    This does not work:
    PHP Code:
                     sg.columns[index].setSize(width); 
    Thanks,
    Stefan

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    7,185
    Vote Rating
    194
    scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold

      0  

    Default


    Have a look at: grid.headerCt

    Scott.

  3. #3
    Ext JS Premium Member
    Join Date
    Nov 2010
    Location
    Rudolstadt, Germany
    Posts
    51
    Vote Rating
    0
    astuteq is on a distinguished road

      0  

    Default


    Thanks for the reply.
    This ends with the same error I get with what I have tried before.

    I tried:
    PHP Code:
    grid.headerCt.getHeaderAtIndex(0).setWidth(100
    I get the error:

    PHP Code:
    TypeError'undefined' is not an object (evaluating 'viewContext.tableContext.getProp')    ColumnLayout.js:101 
    Is this the correct way to do the resizing?

    Stefan

  4. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    7,185
    Vote Rating
    194
    scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold

      0  

    Default


    See the following:

    Code:
    Ext.create('Ext.data.Store', {
        storeId:'simpsonsStore',
        fields:['name', 'email', 'change'],
        data:{'items':[
            { 'name': 'Lisa',  "email":"lisa@simpsons.com",  "change":100  },
            { 'name': 'Bart', "email":"bart@simpsons.com", "change":-20  },
            { 'name': 'Homer', "email":"home@simpsons.com",  "change":23   },
            { 'name': 'Marge', "email":"marge@simpsons.com", "change":-11   }
        ]},
        proxy: {
            type: 'memory',
            reader: {
                type: 'json',
                root: 'items'
            }
        }
    });
    
    var grid = Ext.create('Ext.grid.Panel', {
        title: 'Simpsons',
        store: Ext.data.StoreManager.lookup('simpsonsStore'),
        columns: [
            { header: 'Name',  dataIndex: 'name' },
            { header: 'Email', dataIndex: 'email', flex: 1 },
            { header: 'Change', dataIndex: 'change', tdCls: 'x-change-cell' }
        ],
        height: 200,
        width: 400,
        renderTo: Ext.getBody()
    });
    
    Ext.create('Ext.Button', {
        text: 'Click me',
        renderTo: Ext.getBody(),
        handler: function() {
            grid.headerCt.items.items[0].setWidth(300);
        }
    });
    ​
    Scott.

  5. #5
    Ext JS Premium Member
    Join Date
    Nov 2010
    Location
    Rudolstadt, Germany
    Posts
    51
    Vote Rating
    0
    astuteq is on a distinguished road

      0  

    Default


    Hi Scott,
    thanks for the reply.

    What I forgot to mention is that I do not show the headers of the. Exactly this is the problem.
    If you hide the headers, your suggested solution does not work.

    So, I have no idea how to solve this issue.

    Stefan

  6. #6
    Sencha User tempvalue's Avatar
    Join Date
    Apr 2012
    Posts
    22
    Vote Rating
    0
    tempvalue is on a distinguished road

      0  

    Default


    I thing you can use gridpanel columns -> items or columns itself for this purpose.(in some examples columns:{items:[] } is used instead of columns:[])

    Each column item has a width property. After you create your gridpanel you can reach your columns object. In this array find items(or if columns is an array use it directly) and for any item you can call setWidth(px).

    An example columns object:

    columns:{ items:[{ text:"Column A" dataIndex:"field_A"},{ text:"Column B", dataIndex:"field_B"},...], defaults:{ flex:1}}

    An example columns array from sencha web site:

    columns:[{ header:'Name', dataIndex:'name', sortable:false, hideable:false, flex:1},{ header:'Email', dataIndex:'email', hidden:true},{ header:'Phone', dataIndex:'phone', width:100}]




  7. #7
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    15,087
    Vote Rating
    97
    evant is a splendid one to behold evant is a splendid one to behold evant is a splendid one to behold evant is a splendid one to behold evant is a splendid one to behold evant is a splendid one to behold evant is a splendid one to behold

      0  

    Default


    @OP That certainly looks like a bug. Will check into it.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  8. #8
    Ext JS Premium Member
    Join Date
    Nov 2010
    Location
    Rudolstadt, Germany
    Posts
    51
    Vote Rating
    0
    astuteq is on a distinguished road

      0  

    Default


    Thanks!

    I have just verified that it is a bug.

    Double-checked with version 4.0.7 - Scott's example is working as explained.
    Switching to 4.1.1 - the example does not work as soon as "hideHeaders" is true.

    Please move this to the bug forum.

    Stefan

  9. #9
    Sencha User Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    683
    Vote Rating
    62
    Daniil is a jewel in the rough Daniil is a jewel in the rough Daniil is a jewel in the rough Daniil is a jewel in the rough

      0  

    Default


    +1

    I am getting the same error when a grid is initially rendered. Though I am in trouble to reproduce it with simple example.

    For now, I worked it around replacing
    Code:
    if (viewContext && !ownerContext.state.overflowAdjust.width && !ownerContext.gridContext.heightModel.shrinkWrap) {
    with
    Code:
    if (viewContext && viewContext.tableContext && !ownerContext.state.overflowAdjust.width && !ownerContext.gridContext.heightModel.shrinkWrap) {
    within the calculate function of the Ext.grid.ColumnLayout class.

    I.e. added the check
    Code:
    && viewContext.tableContext

Tags for this Thread