or even better: private function separatorMouseDragHandler(event:GridEvent):void { const headerGroup:GridColumnHeaderGroup = event.currentTarget as GridColumnHeaderGroup; if (headerGroup.dataGrid.columnsLength > 1 && event.columnIndex < event.grid.columns.length -1) { dragging = true; } }
private static const BOUND_LIMIT:int = 5; private function separatorMouseUpHandler(event:GridEvent):void { if (dragging) { dragging = false; const columnIndex:int = event.columnIndex; const headerGroup:GridColumnHeaderGroup = event.currentTarget as GridColumnHeaderGroup; const grid:Grid = event.grid; const visibleColumnIndices:Vector.<int> = grid.getVisibleColumnIndices(); const isVisible:Boolean = visibleColumnIndices.indexOf(columnIndex) > -1; if (visibleColumnIndices.length >= columnIndex + 1 && isVisible) { const dimensions:GridDimensions = grid.mx_internal::gridDimensions; const visibleColumnsWidthBeforeOur:Number = dimensions.getContentWidth(columnIndex); const visibleColumnsWidthUpToOur:Number = dimensions.getContentWidth(columnIndex + 1); if (visibleColumnsWidthUpToOur + BOUND_LIMIT > grid.width) { const newWidth:Number = grid.width - visibleColumnsWidthBeforeOur - BOUND_LIMIT; event.column.width = newWidth; } } } } Note: I used const instead of var because I was doing java today but there's no differences in AS3, they are compiled in the same bytecode. Frédéric THOMAS > From: webdoubl...@hotmail.com > To: dev@flex.apache.org > Subject: RE: Spark datagrid Issue. > Date: Sat, 7 Jun 2014 15:02:19 +0100 > > Hi Saju, > > I guess this topic would fit better in the user mailing list, hower, not sure > I understood your question, anyway I assumed you meant drag (instead of > scroll) the header because in a Spark DataGrid, the header is not drag-able, > so, to restrict the size of the header to make at least one other column > header to stay visible, I would do something like this: > > <?xml version="1.0" encoding="utf-8"?> > <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" > xmlns:s="library://ns.adobe.com/flex/spark" > xmlns:mx="library://ns.adobe.com/flex/mx" > initialize="initData()"> > <fx:Script> > <![CDATA[ > import mx.collections.*; > import mx.events.FlexEvent; > > import spark.components.Grid; > > import spark.components.GridColumnHeaderGroup; > import spark.components.gridClasses.GridDimensions; > > import spark.events.GridEvent; > > import mx.core.mx_internal; > > private var dgArray:Array = [ > {Artist: 'Pavement', Album: 'Slanted and Enchanted', Price: > 11.99}, > {Artist: 'Pavement', Album: 'Brighten the Corners', Price: 11.99} > ]; > [Bindable] > public var initDG:ArrayCollection; > private var dragging:Boolean; > // Initialize initDG variable from the Array. > public function initData():void { > initDG = new ArrayCollection(dgArray); > } > > private function myGrid_creationCompleteHandler(event:FlexEvent):void > { > var dg:DataGrid = event.currentTarget as DataGrid; > dg.removeEventListener(FlexEvent.CREATION_COMPLETE, > myGrid_creationCompleteHandler); > > > dg.columnHeaderGroup.addEventListener(GridEvent.SEPARATOR_MOUSE_DRAG, > separatorMouseDragHandler); > > dg.columnHeaderGroup.addEventListener(GridEvent.SEPARATOR_MOUSE_UP, > separatorMouseUpHandler); > } > > private function separatorMouseDragHandler(event:GridEvent):void { > const headerGroup:GridColumnHeaderGroup = event.currentTarget as > GridColumnHeaderGroup; > if (headerGroup.dataGrid.columnsLength > 1) { > dragging = true; > } > } > > private static const BOUND_SPACE:int = 5; > > private function separatorMouseUpHandler(event:GridEvent):void { > if (dragging) { > dragging = false; > const columnIndex:int = event.columnIndex; > const headerGroup:GridColumnHeaderGroup = event.currentTarget > as GridColumnHeaderGroup; > const grid:Grid = event.grid; > const visibleColumnIndices:Vector.<int> = > grid.getVisibleColumnIndices(); > const isVisible:Boolean = > visibleColumnIndices.indexOf(columnIndex) > -1; > if (visibleColumnIndices.length >= columnIndex + 1 && > isVisible) { > const visibleColumnsWidthBeforeOur:Number = > grid.mx_internal::gridDimensions.getContentWidth(columnIndex); > const visibleColumnsWidthUpToOur:Number = > grid.mx_internal::gridDimensions.getContentWidth(columnIndex + 1); > if (visibleColumnsWidthUpToOur + BOUND_SPACE > > grid.width) { > const newWidth:Number = visibleColumnsWidthUpToOur - > visibleColumnsWidthBeforeOur - BOUND_SPACE; > event.column.width = newWidth; > } > } > } > } > ]]> > </fx:Script> > <s:DataGrid id="myGrid" > width="350" height="200" > dataProvider="{initDG}" > horizontalScrollPolicy="off" > creationComplete="myGrid_creationCompleteHandler(event)"/> > </s:WindowedApplication> > > HTH, > Frédéric THOMAS > > > Date: Sat, 7 Jun 2014 16:23:16 +0530 > > Subject: Fwd: Spark datagrid Issue. > > From: sathikeshj...@gmail.com > > To: dev@flex.apache.org > > > > Any help in this regard.. > > > > -- > > Saju Thankathurai > > > > Sent from my Samsung Galaxy Ace. > > ---------- Forwarded message ---------- > > From: "Saju Thankathurai" <sathikeshj...@gmail.com> > > Date: 7 Jun 2014 08:06 > > Subject: Spark datagrid Issue. > > To: "us...@flex.apache.org" <us...@flex.apache.org> > > > > Hi, > > > > I have a spark flex datagrid. I have set its horizontalscrollpolicy to off. > > When i scroll the header towards right completely, the header is moved and > > is not visible. This makes an impression that there are no more columns in > > the grid. > > > > Is there a way to restrict the columns to a certain limit towards right > > when scrolling > > > > Grid has 3 columns > > [1]. > > https://drive.google.com/file/d/0ByEkeIgKzyCaOXlVaDJ0ckhHLWM/edit?usp=sharing > > > > > > After scrolling the 2nd column towards right, It makes an impression that > > there is only one column available. > > [2] > > https://drive.google.com/file/d/0ByEkeIgKzyCaUkR4WV91cDE1Y0E/edit?usp=sharing > > > > Code: > > > > <?xml version="1.0" encoding="utf-8"?> > > <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" > > xmlns:s="library://ns.adobe.com/flex/spark" > > xmlns:mx="library://ns.adobe.com/flex/mx" > > initialize="initData()"> > > <fx:Script> > > <![CDATA[ > > import mx.collections.*; > > private var dgArray:Array = [ > > {Artist:'Pavement', Album:'Slanted and Enchanted', Price:11.99}, > > {Artist:'Pavement', Album:'Brighten the Corners', Price:11.99}]; > > [Bindable] > > public var initDG:ArrayCollection; > > // Initialize initDG variable from the Array. > > public function initData():void { > > initDG = new ArrayCollection(dgArray); > > } > > ]]> > > </fx:Script> > > <s:DataGrid id="myGrid" > > width="350" height="200" > > dataProvider="{initDG}" > > horizontalScrollPolicy="off"/> > > </s:WindowedApplication> > > > > > > > > -- > > > > Regards > > Saju Thankathurai, >