Flex 3 - How Do I Display dynamic icons in each row of datagrid (ex. PDF, Word,Excel)

Flex 3 - How Do I Display dynamic icons in each row of datagrid (ex. PDF, Word,Excel)
This is for a list of files that the user uploads, I need to show the proper Icon based on all of the different file types that may be uploaded by the end user.
AEPUSERAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mplordCommented:
Breaking the problem into two:
* Acquire icon images
* Display images in datagrid

For the first point, if you're using Air not Flex, you can grab the icon image directly from the a File object.
However if you're intending this to be Flex only, the File class is not available and you'll have to create your own store of icons for different file formats.

For the datagrid, I'd create a component container for the image, and use this as an itemrenderer, dynamically switching which image the image control should display based on the extension of the filename in your underlying dataset.
0
AEPUSERAuthor Commented:
Thank you for the reply & I have done this in .net code, adding controls as Image controls and setting the image URL accordingly, but... Can you show/paste some code that demonstrates how to access the individual image URL locations Using Flex 3 only.

Much Appreciated!
0
mplordCommented:
Here's an example - I haven't provided the actual icon assets though, these could be png images in a folder called assets under your src folder.


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
 
	<mx:Script>
		<![CDATA[
			[Bindable] public var filelist:XML = 
				<files>
					<file name="word.doc"/>
					<file name="excel.xls"/>
				</files>
		]]>
	</mx:Script>
 
	<mx:DataGrid horizontalCenter="0" verticalCenter="0" dataProvider="{filelist.file}">
		<mx:columns>
			<mx:DataGridColumn headerText="Icon" dataField="@name">
				<mx:itemRenderer>
					<mx:Component>
						<mx:HBox width="100%" height="100%" horizontalAlign="center">
							<mx:Image id="iconImage" source="" width="16" height="16"/>
						
							<mx:Script>
								<![CDATA[
									override public function set data(value:Object):void
						            {
						                if(value != null)
						                {
						                    super.data = value;
						                    var filename:String = (value as XML).@name;
						                    
						                    switch(filename.substr(filename.indexOf(".",0)))
						                    {
						                    	case ".xls":
						                    		iconImage.source = "./assets/excel.png";
						                    		break;
						                    	case ".doc":
						                    		iconImage.source = "./assets/word.png";
						                    		break;
											}
						                }
						            }
								]]>
							</mx:Script>
						</mx:HBox>
					</mx:Component>
				</mx:itemRenderer>
			</mx:DataGridColumn>
			<mx:DataGridColumn headerText="Filename" dataField="@name"/>
		</mx:columns>
	</mx:DataGrid>
	
</mx:Application>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mplordCommented:
Polite request for an update - please remember to close questions if you're issue is resolved, or reply if you need further assistance ;)
0
mplordCommented:
We volunteer our time to help you, you could at least close the question when you've taken what you need.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Flex

From novice to tech pro — start learning today.