Results 1 to 4 of 4

Thread: Grid add columns dynamically

  1. #1
    Sencha User
    Join Date
    Aug 2009
    Posts
    87

    Default Grid add columns dynamically

    Hi,

    I wondered if it's possible to add columns to the grid dynamically?

    My grid has to get an array with predefined columns to add.

    For example I've got a custom Ext.grid.Column (with predefined id: 'customColumn') -> if I instantiate the grid like this:
    Code:
    var grid = new My.grid.GridPanel({
        ...
        actions: ['customColumn'],
        ...
    });
    I want to add the column to the grid (the best would be if I could also define the position).
    Is there no addColumn() function to handle this?


    Thanks!

  2. #2
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    See here.

  3. #3
    Sencha User
    Join Date
    Aug 2009
    Posts
    87

    Default

    Thanks,

    but I have no store field for the column.
    This doesn't work correctly.

    I tried some things and now my code is this:
    Code:
    Ext.override(Ext.grid.GridPanel, {
      initComponent: Ext.grid.GridPanel.prototype.initComponent.createSequence(function() {
        var col = new My.grid.Column();
        
        // this function inserts the column to the defined index in colModel.config using colModel.setConfig function
        this.colModel.insertColumn(col, 1);
      })
    });
    This also doesn't work correctly, because the colModel.columns won't be updated.

    This means the resulting colModel contains an array (length = 3) in columns index and an array (length = 4) in config index.

    How do I update the colModel completely?

  4. #4
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    The code I posted is for modifying the columns after the grid is rendered.

    In initComponent the grid isn't rendered yet, so you could simply push() your columns in the specified columns array.

Posting Permissions

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