Results 1 to 4 of 4

Thread: ColumnModel.setConfig sets editor property to null

  1. #1

    Default ColumnModel.setConfig sets editor property to null

    I have the problem that after a call to ColumnModel.setConfig the editor properties of the columns are set to null. This thread has already been posted but I forgot to format the testcode. Thanks for any help!

    Hi, is there a best practice to customize a grid programmatically?

    I would like to set the following options in an existing edit grid:
    • order of columns
    • which columns to hide/display
    • column width
    • [sort direction]
    My approach was to loop through the configured columns of the columnModel and create a new configuration array by copying+modifying the original columns. Then I set the new configuration via

    grid.colModel.setConfig(newColumnConfig, false);

    Unfortunately after the call the editor option of the columns is set to null which results in a non-editable grid. Before the call the columns in the configuration have a valid editor set. So it seems ExtJs sets the editors of the columns to null. But why? How can I customize it and still have it editable?

    Thanks in advance.

    Here is my test code:


    Code:
     
    function customizeGrid(grid) {
    var columnData = [ { id: "price", width: 100, sort: 'ASC' }, { id: "availDate", width: 200, sort: 'ASC' }, { id: "light", width: 50, sort: 'DES' } ];
    var newColumnConfig = new Array(); var index = 0;
    // copy requested columns for (var i = 0; i < columnData.length; i++) {
    var column = grid.colModel.getColumnById(columnData[i].id); if (column) { // copy column to new configuration newColumnConfig[index] = column; // update newColumnConfig[index].hidden = false; newColumnConfig[index].width = columnData[i].width; index++;
    // set flag to indicate column is already copied column.copied = true; } }
    // copy remaining columns (hidden) for (var i = 0; i < grid.colModel.config.length; i++) {
    var column = grid.colModel.config[i]; if (!column.copied) {
    newColumnConfig[index] = column; newColumnConfig[index].hidden = true; index++; } }
    grid.colModel.setConfig(newColumnConfig, false); }
    Code:
    
    


  2. #2
    Sencha Premium User mankz's Avatar
    Join Date
    Nov 2007
    Location
    Stockholm, Sweden
    Posts
    3,153

    Default

    Here's the code you'll have to override.

    Code:
    setConfig : function(config, initial){
            var i, c, len;
            if(!initial){ 
                delete this.totalWidth;
                for(i = 0, len = this.config.length; i < len; i++){
                    c = this.config[i];
                    if(c.setEditor){
                        
                        c.setEditor(null);
                    }
                }
            }
    
            
            this.defaults = Ext.apply({
                width: this.defaultWidth,
                sortable: this.defaultSortable
            }, this.defaults);
    
            this.config = config;
            this.lookup = {};
    
            for(i = 0, len = config.length; i < len; i++){
                c = Ext.applyIf(config[i], this.defaults);
                
                if(Ext.isEmpty(c.id)){
                    c.id = i;
                }
                if(!c.isColumn){
                    var Cls = Ext.grid.Column.types[c.xtype || 'gridcolumn'];
                    c = new Cls(c);
                    config[i] = c;
                }
                this.lookup[c.id] = c;
            }
            if(!initial){
                this.fireEvent('configchange', this);
            }
        },

  3. #3

    Default

    Thanks for your reply. I am not sure though if overriding setConfig is really okay, since it would change the default behaviour (e.g. the origninal code calls destroy for each column). There may also be problems in the future when upgrading to another ExtJs version.
    Is setting the editor to null in setConfig a bug then?
    Isn't there another option to customize the grid with a new configuration (without loosing editability)?

    Thank you.

  4. #4
    Sencha Premium User mankz's Avatar
    Join Date
    Nov 2007
    Location
    Stockholm, Sweden
    Posts
    3,153

    Default

    It's not a bug, it's just cleaning up before setting the new config (which might not include editors). To get editability with your new config, you'll need to create new editors (if you don't want to override the default behavior)

Similar Threads

  1. Replies: 11
    Last Post: 3 Jan 2011, 12:31 PM
  2. Replies: 0
    Last Post: 21 May 2010, 6:41 AM
  3. problem with ColumnModel.setConfig
    By aj3423 in forum Ext 3.x: Help & Discussion
    Replies: 5
    Last Post: 14 May 2009, 6:55 PM
  4. Update to ColumnModel setConfig method
    By precariouspanther in forum Community Discussion
    Replies: 0
    Last Post: 16 Mar 2008, 5:30 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
  •