views:

636

answers:

2

So, I have an AdvancedDataGrid that needs to live inside a Canvas. My problem is that when you do something like this you get two sets of scroll bars. Also, the horizontal scroll bar for the AdvancedDataGrid changes size as you scroll right to left and will not let you scroll ALL the way to the right, which seems odd.

I've turned horizontal scrolling off on the AdvancedDataGrid and let only the Canvas handle it. When I do that, however, the columns don't allow themselves to be resizable. Ugh.

My current "best" solution is to have the AdvancedDataGrid handle the vertical scrolling and the Canvas handle the horizontal scrolling, but this just seems insane, not to mention I get the problem I mentioned above where I can no longer resize columns.

Any help is greatly appreciated! Thanks!

+2  A: 

The AdvancedDataGrid's horizontal scrolling is somewhat peculiar, in that it sizes its horizontal scroll thumb based on the width of the visible columns. You actually can drag the thumb to the end, but it might take a couple of tries. (I know, I know ...)

Remember that in the AdvancedDataGrid there is nothing actually rendered outside the viewport, so any sizing is just an educated (well, somewhat educated) guess. Adobe does this so that huge grids don't bog down to a crawl (imagine running measure methods on 15,000 cells' itemRenderers every time you resized the window).

My advice is to turn off both vertical and horizontal scroll policies in the Canvas and allow the scrolling to be handled in the ADG. It's ugly, but it beats the alternative. The ADG is a cumbersome, cantankerous contraption anyway, which may be why Adobe has open-sourced it. I have sworn many times I would never use it again. I've been able to keep that vow only until the next time I needed its features. Which is about every week.

Robusto
Thanks for the response.When you say I caaan drag it all the way to the right, this is kind of the case. What is happening, for whatever reason, is that the Canvas is slightly bigger than the grid, even tho the Grid is the only thing inside the Canvas! The reason I can't scroll all the way over, as mentioned before, is because the Canvas is scrolled all the way to the left and the only way to get all the way to the right is to have two scroll bars... what the hell?!Any ideas why the Canvas would be bigger? Both things width and height are set to 100%
There is probably some invisible border skin around the AdvancedDataGrid. In any case, set horizontalScrollPolicy="false" and verticalScrollPolicy="false" on your canvas. And as much as I admire www.Flextras.com elsewhere, I would not advise following his suggestion of letting the canvas handling the scrolling here. That would defeat the ADG rendering optimizations and reduce performance, IMO.
Robusto
Ok, I fixed the issue I was having earlier by setting the datagrid's width to "this.width" instead of 100% (inside the Canvas) so now I can actually get the end of the grid. It's making the last column in the grid much bigger than the rest of the columns in the grid now...any ideas on that? AdvancedDataGrid is a terrible terrible thing.
@Robusto; +1. That's a very good point about the use of Renderers and renderer recycling and something I had not considered. this makes me see an alternate flaw in my answer; that sizing the ADG using measuredHeight and measuredWidth will most likely do so for the "default" number of Renderers, which may not remove scroll bars from the ADG. @user Remember that a component's parent always set its' height. The canvases parent will set it's height and width without consideration for the canvas's children (ADG) [depending on the measure method]
www.Flextras.com
@user379467: Yes. I always add a "dummy" last column with no data, no headerText, and a width of 5, minWidth of 0. It sucks up all the "extra" space so no column gets way huge.
Robusto
A: 

Is the AdvancedDataGrid the only thing in your canvas?

I would size the AdvancedDataGrid to it's full height and width and let the Canvas handle scrolling.

In the canvas, override the updateDisplayList method and do something like this:

protected function updateDisplayList(unscaledWidth: Number, unscaledHeight: Number):void{
 super.updateDisplayList, unscaledHeight);
 this.myAdvancedDataGrid.setActualSize(this.myAdvancedDataGrid.measuredHeight, this.myAdvancedDataGrid.measuredWidth );
}

This way the AdvancedDataGrid should have no scroll bars. However, if it stretches to far down, or too far right the scroll bars will appear in the canvas.

You might benefit from reading up on the Flex Coordinate System. The AdvancedDataGrid is your "Content" while the Canvas would be your local.


I'm adding a full running code sample to demo my suggestion.

This is the canvas component with an AdvancedDataGrid inside it: com.flextras.stackOverflow.CanvasWithGrid

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

    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;

            override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
                super.updateDisplayList(unscaledWidth, unscaledHeight);
                this.myADG.setActualSize(this.myADG.measuredWidth, this.myADG.measuredWidth );
            }

            [Bindable]
            private var dpFlat:ArrayCollection = new ArrayCollection([
                {Region:"Southwest", Territory:"Arizona", 
                    Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000}, 
                {Region:"Southwest", Territory:"Arizona", 
                    Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000},  
                {Region:"Southwest", Territory:"Central California", 
                    Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000},  
                {Region:"Southwest", Territory:"Nevada", 
                    Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000},  
                {Region:"Southwest", Territory:"Northern California", 
                    Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000}, 
                {Region:"Southwest", Territory:"Northern California", 
                    Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000},  
                {Region:"Southwest", Territory:"Southern California", 
                    Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000}, 
                {Region:"Southwest", Territory:"Southern California", 
                    Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}
            ]);

        ]]>
    </fx:Script>

    <mx:AdvancedDataGrid id="myADG" 

                         initialize="gc.refresh();"> <!--  width="100%" height="100%"  -->       
        <mx:dataProvider>
            <mx:GroupingCollection id="gc" source="{dpFlat}">
                <mx:grouping>
                    <mx:Grouping>
                        <mx:GroupingField name="Region"/>
                        <mx:GroupingField name="Territory"/>
                    </mx:Grouping>
                </mx:grouping>
            </mx:GroupingCollection>
        </mx:dataProvider>        

        <mx:columns>
            <mx:AdvancedDataGridColumn dataField="Region"/>
            <mx:AdvancedDataGridColumn dataField="Territory"/>
            <mx:AdvancedDataGridColumn dataField="Territory_Rep"
                                       headerText="Territory Rep"/>
            <mx:AdvancedDataGridColumn dataField="Actual"/>
            <mx:AdvancedDataGridColumn dataField="Estimate"/>
        </mx:columns>
    </mx:AdvancedDataGrid>

</mx:Canvas>

This is the main application file:

<?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" minWidth="955" minHeight="600" xmlns:stackOverflow="com.flextras.stackOverflow.*">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <stackOverflow:CanvasWithGrid width="200" height="200" />


</s:Application>
www.Flextras.com
Hi, thank you for the response. I definitely like the way canvas handles the scrolling over AdvancedDataGrid and in my case performance will not be an issue because the grid will never be incredibly large. However, I was not able to get your code working properly. All this did was make the grid incredibly small. I'm not sure if I was doing something crazy, but for the most part I just copied the code into the Canvas..
Can you show us more code? I'm not actually sure how the AdvancedDataGrid calculates it size.
www.Flextras.com
I added a full running sample to demonstrate my suggestion.
www.Flextras.com