Filter data in Advance Data Grid control Flex

Hi All,

In below example I will show the way we can filter the data in Advance data grid using some Input box control. To filter a data in Advance data grid we can use IHierarchicalCollectionView class which uses  an interface for hierarchical or grouped data. Typically, we use this data with the AdvancedDataGrid control.

Flex Code
<![CDATA[
import mx.collections.HierarchicalData;
import mx.collections.IHierarchicalCollectionView;

// Filter
private function filterTreeData():void{
IHierarchicalCollectionView(myId.dataProvider).filterFunction = myFilterFunc;
IHierarchicalCollectionView(myId.dataProvider).refresh();
}

private function myFilterFunc(item:Object):Boolean {
/*
ColumnOfGrid: is the column in Tree Grid(just change to your column)
*/
if(item.hasOwnProperty(“ColumnOfGrid”) && (item[“ColumnOfGrid”].toString()).substr(0,txt.length).toLowerCase() == txt.text.toLowerCase())
return true;

return false;
}
]]>
</mx:Script>

<mx:AdvancedDataGrid width=”100%” height=”100%” displayItemsExpanded=”true”  defaultLeafIcon=”{null}” id=”myId” >
<mx:dataProvider>
<mx:HierarchicalData source=”{myArrCollection}” />
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn dataField=”ColumnOfGrid”   />
</mx:columns>
</mx:AdvancedDataGrid>

Hope this helps.


Thanks
R Vashi

2 thoughts on “Filter data in Advance Data Grid control Flex

    • Oops, I see what you do now.
      I did not see how the filter was applied to the dataprovider, I expected to see it in the MXML.
      You however assume that filterTreeData() is called from somewhere (not shown in your example).

      This was helpful though, it is sad that the only way to really get flex apps to work is to do a lot of googling and find helpful posts like yours.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s