Flex - 让DataGrid按比例设置各列宽度
有时我们想要对DataGrid的列宽按比例设置,比如第一列占20%,第二列占30%,第三列占50%。但DataGridColumn的width可不能设置百分比的宽度,比如下面这样就无法编译:
其实只要给各个列设置固定宽度,表格自然就会按照这个相互的比例来设置了。比例上面情况就可以这样实现:
<mx:DataGrid width="100%" height="100%"> <mx:columns> <mx:DataGridColumn headerText="列1" dataField="name" width="20%" /> <mx:DataGridColumn headerText="列2" dataField="age" width="30%" /> <mx:DataGridColumn headerText="列3" dataField="job" width="50%"/> </mx:columns> </mx:DataGrid>
其实只要给各个列设置固定宽度,表格自然就会按照这个相互的比例来设置了。比例上面情况就可以这样实现:
<mx:DataGrid width="100%" height="100%"> <mx:columns> <mx:DataGridColumn headerText="列1" dataField="name" width="20" /> <mx:DataGridColumn headerText="列2" dataField="age" width="30" /> <mx:DataGridColumn headerText="列3" dataField="job" width="50"/> </mx:columns> </mx:DataGrid>