Question

i have a AdvancedDataGrid coponent with some custom Rows. I have a limited number of rows visible within the component. The other rows can be accessed via a scrollbar. Within my application i have ha Save & Next Button which saves the actual selected record and iterates the Grid's selected item by 1 until the end. Unfortunately this procedure works only until i reach the end of the visible rows. After that the Grid crashes when i select the not visible row and try to scroll there programatically:

//Bad Crash
this.documentBrowser.dg.selectedIndex = index + 1;
this.documentBrowser.dg.validateNow();
this.documentBrowser.dg.scrollToIndex(this.dg.selectedIndex);

I found out that the next element isn't instanciated in that moment. Is there any possibility to render all items in the grid after loading or to deactivate the lazy rendering?

The stack trace:

TypeError: Error #1010: A term is undefined and has no properties. at mx.controls.listClasses::AdvancedListBase/makeRowsAndColumnsWithExtraRows()[/Users/justinmclean/Documents/ApacheFlexSDK/frameworks/projects/advancedgrids/src/mx/controls/listClasses/AdvancedListBase.as:4008] at mx.controls.listClasses::AdvancedListBase/updateDisplayList()[/Users/justinmclean/Documents/ApacheFlexSDK/frameworks/projects/advancedgrids/src/mx/controls/listClasses/AdvancedListBase.as:3582] at mx.controls::AdvancedDataGridBaseEx/updateDisplayList()[/Users/justinmclean/Documents/ApacheFlexSDK/frameworks/projects/advancedgrids/src/mx/controls/AdvancedDataGridBaseEx.as:2033] at mx.controls::AdvancedDataGrid/updateDisplayList()[/Users/justinmclean/Documents/ApacheFlexSDK/frameworks/projects/advancedgrids/src/mx/controls/AdvancedDataGrid.as:2907] at mx.controls.listClasses::AdvancedListBase/validateDisplayList()[/Users/justinmclean/Documents/ApacheFlexSDK/frameworks/projects/advancedgrids/src/mx/controls/listClasses/AdvancedListBase.as:3480] at mx.managers::LayoutManager/validateDisplayList()[/Users/justinmclean/Documents/ApacheFlexSDK/frameworks/projects/framework/src/mx/managers/LayoutManager.as:744] at mx.managers::LayoutManager/doPhasedInstantiation()[/Users/justinmclean/Documents/ApacheFlexSDK/frameworks/projects/framework/src/mx/managers/LayoutManager.as:827] at mx.managers::LayoutManager/doPhasedInstantiationCallback()[/Users/justinmclean/Documents/ApacheFlexSDK/frameworks/projects/framework/src/mx/managers/LayoutManager.as:1195]

Was it helpful?

Solution

I'm pretty sure that lazy rendering feature re-uses your item renderers as soon as the roll off the screen (to optimize performance). So maybe you only need to do whatever you're doing to the visible ones and it will remain 'done' to all renderer instances?

Are you sure you need to access the ACTUAL visible rows themselves and not the items in your dataProvider that back them? If accessing your backing data is okay, maybe you should iterate through your dataProvider instead.

I made this little application that scrolls to and highlights a row with a function called gotoGridItem(index). I scroll to the item before trying to set the selectedIndex--maybe that was what gave you the crash?

Here's my code:

<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">

    <mx:AdvancedDataGrid id="theGrid" dataProvider="{rowDataItems}" x="50" y="50"/>
    <s:NumericStepper id="rowIndSpr" minimum="0" maximum="{theGrid.dataProvider.length-1}" value="{8}"/>
    <s:Button click="gotoGridItem(int(rowIndSpr.value))" label="Go" y="20" />

    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            [bindable] public var rowDataItems:ArrayCollection = new ArrayCollection([

                //...lots of data items for rows ...

            ]);

            public function gotoGridItem(index:uint):void{


                theGrid.scrollToIndex(index);
                theGrid.selectedIndex = index;
                theGrid.validateNow();
            }
        ]]>

    </fx:Script>
</s:Application>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top