flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Frédéric THOMAS <webdoubl...@hotmail.com>
Subject RE: Spark datagrid Issue.
Date Sat, 07 Jun 2014 14:02:19 GMT
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: sathikeshjith@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" <sathikeshjith@gmail.com>
> Date: 7 Jun 2014 08:06
> Subject: Spark datagrid Issue.
> To: "users@flex.apache.org" <users@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,
 		 	   		  
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message