在FLEX中更新焦点上的列宽widthdatagrid?

时间:2013-08-29 17:43:57

标签: flex combobox focus advanceddatagrid

我在高级数据网格中有组合框,我希望当用户点击当前列时,列会变得更宽,当用户获得另一列时,相同而前一个列失去焦点时会获得默认值< / p>

我正在阅读'关注焦点但是我找不到一个好的例子......

有人,有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我可以告诉您如何调整已单击其项目的列的大小。我确信有一种更简单的方法可以做到这一点......

为您的数据网格提供项目点击事件:

<mx:AdvancedDataGrid
     name="datagrid"
     id="datagrid"
     width="50%"
     columns="{columnsArr}"
     dataProvider="{dataProv}"
     itemClick="resizeCol(event)"
    />

public function resizeCol(event:ListEvent):void
        {
            //The new width for the column which has been clicked
            var newColumnWidth:Number = 300;
            //Calculate the width to resize the other columns to; width of the datagrid 
            //divided by how many columns are in the DG (minus the one we are resizing)
            //Then, subtracted by half the width of the column we are resizing
            var equalColWidth:Number = Math.floor(this.datagrid.width / (this.datagrid.columns.length -1));
            equalColWidth -= (newColumnWidth/2);
            //Grab the column to resize from the event object
            var column:AdvancedDataGridColumn = this.datagrid.columns[event.columnIndex] as AdvancedDataGridColumn;

            //Loop columns, make the column which will change to the new width, 
            //Make the other columns equal in size.
            for each(var col:AdvancedDataGridColumn in this.datagrid.columns)
            {
                if(col == column)
                {
                    column.width = newColumnWidth;
                }
                else
                {
                    col.width = equalColWidth;
                }
            }

        }