0
votes

This is resize is scaling by: stage.scaleMode = StageScaleMode.SHOW_ALL; // No Good cause just the Datagrids need to scale

I am trying to find a way to Scale (either font or scaleX&Y) a DataGrid (with requestedMinRowCount = requestedMaxRowCount = requestedRowCount = dataProviderLength), so that it would Always show all the Rows (so no scrollers).

A Solution I came up with for Scaling is:

protected function thisDatagrid_resizeHandler(event:ResizeEvent):void
{
   if (event.oldWidth < this.width) {
     this.setStyle('fontSize', this.getStyle('fontSize') + 0.5);
   } else if (event.oldWidth > this.width) {
      this.setStyle('fontSize', this.getStyle('fontSize') - 0.5);
   }
   this.minWidth = this.measuredMinWidth;
}

While the code above actually does resize the text (hence the cell, column and grid) on Resize, the problem I am getting is when the rescale happens vertically.

For the requestedRowCount to work, there should not be a fixed height set on the Datagrid. So I am wondering what is the way to get the grid to constantly show all it's rows & columns as it scales (even if resized vertically)?

Another Option would be overriding updateDisplayList, though not straight forward for resizing.

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {

     //super.updateDisplayList(unscaledWidth, unscaledHeight);              
     trace('oldWidth: ' + oldWidth + '  | unscaledWidth: ' + unscaledWidth + '  | parentWidth: ' + this.parent.width);
     trace('oldHeight: ' + oldHeight + '  | unscaledHeight: ' + unscaledHeight + '  | parentHeight: ' + this.parent.height);
     trace('Potential ScaleX: ' + (unscaledWidth - oldWidth)/unscaledWidth);
     trace('Potential ScaleY: ' + (unscaledHeight - oldHeight)/unscaledHeight);
     trace('----------------------------------------------------');
     /* scaleX = (unscaledWidth - oldWidth)/unscaledWidth;
     scaleY = (unscaledHeight - oldHeight)/unscaledHeight; */

     //super.updateDisplayList(unscaledWidth, unscaledHeight);
}

The problem with this if I uncomment scaleX & scaleY, it'll loop forever...

2

2 Answers

1
votes

I might be misunderstanding you but couldn't you just use:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <s:DataGrid
        id="grid"
        width="100%"
        requestedRowCount="{grid.dataProvider.length}"
        rowHeight="24"
        fontSize="12"
        horizontalScrollPolicy="off"
        verticalScrollPolicy="off">

        <s:dataProvider>
            <s:ArrayCollection>
                <s:source>
                    <fx:Object id="one" label="One" value="1" />
                    <fx:Object id="two" label="Two" value="2" />
                    <fx:Object id="three" label="Three" value="3" />
                </s:source>
            </s:ArrayCollection>
        </s:dataProvider>

        <s:columns>
            <s:ArrayCollection>
                <s:GridColumn dataField="label" headerText="Label" />
                <s:GridColumn dataField="value" headerText="Value" />
            </s:ArrayCollection>
        </s:columns>
    </s:DataGrid>
</s:Application>
0
votes

The best (and most performant way is to use the layout of a group where the Datagrids would be located, and apply a layout like the one below:

ex: ScaleOneLayout.as

import mx.core.UIComponent;

import spark.layouts.BasicLayout;

public class ScaleOneLayout extends BasicLayout
{
    public function ScaleOneLayout()
    {
        super();
    }

    override public function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
   {
        var child:UIComponent;
        child = target.getElementAt(0) as UIComponent;
        child.setLayoutBoundsSize(child.getPreferredBoundsWidth(), child.getPreferredBoundsHeight());
        child.scaleX = unscaledWidth / child.width;
        child.scaleY = unscaledHeight / child.height;
    }
}