3

I have a problem with Adobe Flex. I have AdvancedDataGrid as a treeview, which data provider is GroupingCollection2. In this grid I have documents, which are grouped by 3 tags. When user modifies any document I have to refresh whole grid. And here is my problem. After the refresh my grid is scrolled to the beginning. I managed to scroll it to previous index but it's not working good. If any node above edited document was collapsed then after the refresh all nodes are expanded and previous index is not targeting the same document. How can I remember the selected item and scroll to it?

I have dificulties with this mainly because there is more rows in data grid than items in source. It's like this, because all "folders" in grid are also counted as row.

This is my AdvancedDataGrid:

<mx:AdvancedDataGrid  visible="{entityId > 0}" height="100%" variableRowHeight="true" width="90%" left="5" right="5" bottom="5" top="70" id="_dg" doubleClickEnabled="false" doubleClick="onDgDoubleClick(event)"  updateComplete="onUpdateComplete(event)">
            <mx:dataProvider>
                <mx:GroupingCollection2 id="_groupper" source="{getTemplateFilesResponder.lastResult}">
                    <mx:grouping>
                        <mx:Grouping>
                            <mx:GroupingField name="Type1" groupingFunction="getTypeLabel" id="_groupingField"  />
                            <mx:GroupingField name="Type2" groupingFunction="getTypeLabel" />
                            <mx:GroupingField name="Type3" groupingFunction="getTypeLabel"/>
                        </mx:Grouping>
                    </mx:grouping>
                </mx:GroupingCollection2>
            </mx:dataProvider>    
            <mx:columns>        
                <mx:AdvancedDataGridColumn headerText="{resourceManager.getString('biawizard','file.18')}" dataField="OriginalFileName" wordWrap="true" />
                <mx:AdvancedDataGridColumn headerText="{resourceManager.getString('biawizard','list.labeldescription')}" dataField="Comments" wordWrap="true" />

                <mx:AdvancedDataGridColumn headerText="{resourceManager.getString('biawizard','filelistform.Version')}" dataField="Version" wordWrap="true" />
                <mx:AdvancedDataGridColumn headerText="{resourceManager.getString('biawizard','filelistform.Status')}" dataField="Status" labelFunction="getStatusLabel" wordWrap="true" />

            </mx:columns>
        </mx:AdvancedDataGrid>

Does anybody have any idea how can I do ot correctly?

1 Answer 1

1

you could try a trick, but as you say not working properly, the issue of assigning an index. You could save the index of selection to know which was the last item selected and then assign it after you run your command through events.

[Bindable] private var objLastSelectIndex:int;

private function init()
{
    FlexGlobals.topLevelApplication.addEventListener(Controller.EVENT_YOUR_EVENT_REFRESH, onScrollSett);
}

private function onItemClickDataGrid(e:Event):void 
{
    this.objLastSelectIndex = this.adgData.selectedIndex;
}

private function onScrollSett(e:Event):void
{
    try
    {
        this.adgData.selectedIndex = this.objLastSelectIndex
        this.adgData.validateNow();
        this.adgData.scrollToIndex(this.objLastSelectIndex);    
    }
    catch(err:Error)
    {
        //TODO: ERROR IN INDEX SETTING
    }

}


<mx:AdvancedDataGrid id="adgData" itemClick="{onClickItemDataGrid(event)}" />

Also if you use an ArrayCollection you can try to play with the source of it, assigning the value directly, what you do to the grid is not redrawn.

regars.

5
  • I was doing something like this, but as I wrote it's not working properly. When I have collapsed nodes after the refresh they are expanded the saved index isn't correct. If I want to do it like this, the index should be like this: saved index + number of documents in collapsed nodes above edited document. Nov 19, 2013 at 15:15
  • If I understand you've had the same problem many times why I avoid such controls and make two grids to avoid me the problem. Equally as you were saying, it is almost impossible to generate the correct index. Tried to use the "source" directly?
    – matilu
    Nov 19, 2013 at 15:26
  • This is the first time I have this problem, I just was working on this before I posted my question on stack. I was trying to use source, but it doesn't contain nodes, only documents, so index is still messed up. Nov 19, 2013 at 15:31
  • Just think the work you do would ensure that you do not always work. Maybe you have to see other options of presentation, not to get caught up in this. I hope someone can help. If I find something I share.
    – matilu
    Nov 19, 2013 at 15:38
  • Thanks. I hope I will do it;) Nov 19, 2013 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.