1. #1
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,496
    Vote Rating
    44
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default Bug in ColumnModel

    Bug in ColumnModel


    Constructor contains:

    Code:
        for(var i = 0, len = config.length; i < len; i++){
            var c = config[i];
            if(typeof c.dataIndex == "undefined"){
                c.dataIndex = i;
            }
            if(typeof c.renderer == "string"){
                c.renderer = Ext.util.Format[c.renderer];
            }
            if(typeof c.id == "undefined"){
                c.id = i;
            }
            if(c.editor && c.editor.isFormField){
                c.editor = new Ext.grid.GridEditor(c.editor);
            }
            this.lookup[c.id] = c;
        }
    The code in bold used to be valid in yui-ext 0.33, but now, the dataIndex must be a name because it is accessed from the Ext.data.Record's data object by that property, and that is not an instance of Array.

    The code in GridView has

    Code:
            var cs = [];
            for(var i = 0; i < colCount; i++){
                var name = cm.getDataIndex(i);
                cs[i] = {
                    name : typeof name == 'undefined' ? ds.fields.get(i).name : name,
                    renderer : cm.getRenderer(i),
                    id : cm.getColumnId(i),
                    locked : cm.isLocked(i)
                };
            }
    Which allows you NOT to specify dataIndex in your ColumnModel, and uses the ordinal position instead, but "typeof name" will never be undefined, so it will stay as a number, so later, in doRender:

    Code:
                            p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
    r.data[/* a number*/] === undefined.

    To exhibit this, change the ColumnModel definition in examples/grid.array-grid.js to remove the dataIndex properties:

    Code:
            var colModel = new Ext.grid.ColumnModel([
    			{id:'company',header: "Company", width: 160, sortable: true, locked:false},
    			{header: "Price", width: 75, sortable: true, renderer: Ext.util.Format.usMoney},
    			{header: "Change", width: 75, sortable: true, renderer: change},
    			{header: "% Change", width: 75, sortable: true, renderer: pctChange},
    			{header: "Last Updated", width: 85, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y')}
    		]);

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,496
    Vote Rating
    44
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    I thought I'd fluff this given that it's been here a week.

    The above code implies the intention to allow omitted dataIndex to mean access of the field via its ordinal position, but it does not actually do that.

  3. #3
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    16
    jack.slocum will become famous soon enough

      0  

    Default


    Edit, i see the issue. Let me do a little more investigating.
    Jack Slocum
    Ext JS Founder
    Original author of Ext JS 1, 2 & 3.
    Twitter: @jackslocum
    jack@extjs.com

  4. #4
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,496
    Vote Rating
    44
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    I thought I'd fluff this thread in case it's fallen off the radar.

    Someone has just encountered this in the "Help" forum, they'd used Arrays as row objects, and omitted the dataIndex from their ColumnModel relying on what the docs about DataIndex say, and found that the Grid was not populated.

    I pointed them to the workaround of explicitly setting a dataIndex of 0,1,2 etc... but it's not ideal.

  5. #5
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    16
    jack.slocum will become famous soon enough

      0  

    Default


    This change will be in rev tagged alpha 1.
    Jack Slocum
    Ext JS Founder
    Original author of Ext JS 1, 2 & 3.
    Twitter: @jackslocum
    jack@extjs.com

Thread Participants: 1