Musings on AdvancedDataGrid (Part 5)

english mobile

Up to part 4, I've been talking about the AdvancedDataGrid itself and the properties it has that are supposed to make your life easier, like styleFunction and iconFunction. And they do, once you understand them. But now I'd like to turn my attention to the data source I was using to drive my AdvancedDataGrid (ADG).

My AdvancedDataGrid is being used as a menu on an eLearning application. The application has various tasks that the user must complete. Once a task is complete, it is shown again in review mode, which provides the student with remediation on what he did wrong or right. The student can also view reports of what he did in a given task. So each task will be available in three modes: normal, review, and analysis. The mode will be determined by the top-level container.
To this end, I created an array of MenuContainer Value Objects (VO) that contained a number of Task VO's. I assigned these to a HeirarchicalData dataProvider in the ADG. I immediately realized that the itemClick event just gave me the Task VO, and the Task knew nothing about its parent (and rightly so). Apparently, the itemRenderer also knew nothing about where the Task fell in the data structure, nor anything else in the ADG.

I realized it was a slippery problem, since even if I were to loop through the MenuContainers and find the Task that was selected, I would only find the first instance of it. So I decided to wrap my Task class in another class that had two properties, task and UID. In this class, TaskUID, I simply used UIDUtil to create a UID for this instance of the task.

Once I had that accomplished, I decided to take one more squint at the docs before I built a function to loop through and find my TaskUID. I trolled the language reference only on the word hierarchical. I'd looked at the HierarchicalCollectionView before, but the description implies that this is for making flat collections look hierarchical (heck, it actually says it!). However, this class does include a method, getParentItem(), which looked perfect for my needs.

In a wild leap of faith, I cast the event.currentTarget.dataProvider from the itemClick event from HierarchicalData to HierarchicalCollectionView and the method worked! It gave me a reference to the MenuContainer from the TaskUID. I have no idea what the differences are between those classes, so I wouldn't guarantee all methods would work when you do this kind of casting, but this worked for me!

1 comments:

adicoza786 said...

Hi Amy,

I have found you blog to be pretty useful.So i would like to thank you first.

Coming to my problem.

I am using AdvanceDataGrid to display data in hierarchical fashion.The data is in the form of XML as follows.












I am using lazy loading concept in which I only load one level of hierarchy at a time.I insert the tag as a child tag for row which has children.This makes sure that the expand/collapse icon appears for this row.

I then use the itemOpen event of the advancedatagrid to fetch the children of the clicked item and replace the with the children fetched for the clicked item.

I see that the icons displayed next to each expand/collapse are the same irrespective of hierarchy.

My requirement is that I want to set the icon (instead of folder and file which are show by default) depending on the data.The icon needs to be different for each row whether child or parent and will be governed by the data for that row.

I have tried using itemrenderer which shows the icon properly as follows.















But the lazy loading of hierarchy no more works i.e. The itemOpen events just hangs and i dont know why it happens.

The following is the sample src -





;
private static var _loadingIndicator: XML = ;

private var _clickedNode: XML;

public function loadData() : void {
var test: testCommand = new testCommand( );
test.setCallbacks( getEventsHandleR esult,
getEventsHandleFaul t);
test.getData( );
}

private function getEventsHandleFaul t(e:FaultEvent) :void {

}

private function getEventsHandleResu lt(res:ResultEve nt):void {

var ac:ArrayCollection = ArrayCollection( res.result) ;

_loadingIndicator. @id = 'Loading...' ;
_loadingIndicator. @loadData = 'true';

for each (var foo:Test in ac) {
var _newNode:XML = ;
_newNode.@id = foo.eventHandle. toString( );
_newNode.@name = foo.cellName. toString( );
_newNode.@iconPath = foo.iconPath. toString( );

if (foo.hasChildren. toString( ) == "true") {
_newNode.appendChil d(_loadingIndica tor);
}
_xml.appendChild( _newNode) ;
}

_data = new XMLList(_xml. data);
adg.dataProvider = new HierarchicalData( _data);
}

private function fetchChildren( res:ResultEvent) :void {
var ac:ArrayCollection = ArrayCollection( res.result) ;
_xml =

_loadingIndicator. @id = 'Loading...' ;
_loadingIndicator. @loadData = 'true';

for each (var foo:NGPEventVO in ac) {
var _newNode:XML = ;
_newNode.@id = foo.eventHandle. toString( );
_newNode.@name = foo.cellName. toString( );
_newNode.@iconPath = foo.iconPath. toString( );

if (foo.hasChildren. toString( ) == "true") {
_newNode.appendChil d(_loadingIndica tor);
}
_xml.appendChild( _newNode) ;

}

_clickedNode. replace(" data", _xml.data);
}

private function onItemOpen(event : AdvancedDataGridEve nt):void
{

var children : XMLList =
XML( event.itemRenderer. data).children( );

if ( children.length( ) == 1
&& children[0]. @loadData == "true" ) {

_clickedNode = XML(event.itemRende rer.data) ;

var test : Test = new Test();
test.setCallbacks( fetchChildren, getEventsHandleF ault);
test.getData( );
}
}
]]>