code_junkie

Fit Flex datagrid to data

Nov 13th, 2011
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. <mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
  2. creationComplete="OnCreationComplete()"
  3. paddingTop="0"
  4. paddingBottom="0"
  5. >
  6.  
  7. <mx:Script>
  8. <![CDATA[
  9.  
  10. private function OnCreationComplete():void
  11. {
  12. //setRowHeight(10);
  13. }
  14.  
  15. override protected function setRowHeight(v:Number):void
  16. {
  17. super.setRowHeight(v);
  18. }
  19.  
  20. ]]>
  21. </mx:Script>
  22.  
  23. </mx:DataGrid>
  24.  
  25. <?xml version="1.0" encoding="utf-8"?>
  26. <mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
  27. paddingTop="-3"
  28. paddingBottom="-3"
  29. resize="OnResize(event)"
  30. >
  31.  
  32. <mx:Script>
  33. <![CDATA[
  34. import mx.containers.Panel;
  35. import mx.core.Application;
  36. import mx.events.ResizeEvent;
  37.  
  38. protected function OnResize(event:ResizeEvent):void
  39. {
  40. this.invalidateDisplayList();
  41. }
  42.  
  43. /**
  44. * @private
  45. * Sizes and positions the column headers, columns, and items based on the
  46. * size of the DataGrid.
  47. */
  48. override protected function updateDisplayList(unscaledWidth:Number,
  49. unscaledHeight:Number):void
  50. {
  51. if( this.collection.length > 0 ) // so don't divide by zero
  52. {
  53. var appHeight:Number = Application.application.height;
  54. var appMinusMenuHeight:Number = appHeight - Application.application.hboxPrintBar.height;
  55. var boxHeight:Number = Application.application.vboxViewAll.height;
  56. if( boxHeight > 0 )
  57. {
  58. var gridHeight:Number = (appMinusMenuHeight - this.headerHeight) * 0.93;
  59. var calcHeight:Number = gridHeight / this.collection.length;
  60. var calcHeightFloor:Number = Math.floor( calcHeight );
  61. setRowHeight( calcHeightFloor );
  62. //var p:Panel = this.parent as Panel;
  63. //p.title = calcHeightFloor.toString();
  64. if( calcHeightFloor <= 10 )
  65. this.setStyle("fontSize",calcHeightFloor);
  66. }
  67. }
  68. super.updateDisplayList(unscaledWidth,unscaledHeight);
  69. }
  70.  
  71. ]]>
  72. </mx:Script>
  73.  
  74. </mx:DataGrid>
  75.  
  76. myDataGrid.dataProvider = myArray;
  77. myGrid.rowHeight = Math.floor((myGrid.height - myGrid.headerHeight)/myArray.length);
Add Comment
Please, Sign In to add comment