Solved

How to setproperty of a row in actionscript

Posted on 2009-05-16
5
775 Views
Last Modified: 2012-05-07
I am trying set property of specific rows at runtime in my Flex application. For example based on some runtime conditions I was make the cells of an entire row not editable. Similarly based on some runtime conditions I want to make some rows invisible. I thought mydg.setPropertiesAt would work. but it is giving setPropertiesAt as undefined method. I am not sure which class I should import also not sure if this would address my requirement.
Thanks~
0
Comment
Question by:ganands
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:mplord
Comment Utility
You haven't mentioned if you are working with a DataGrid control? Sounds like it as you mention 'rows' and 'cells' - is this the case? It might sound obvious but it is best to be specific here. If so:

Working with rows takes some advanced coding, depending on what you require, and I see two requirements in your question:
* make a given row completely uneditable
* hide rows

Well, the second (hide rows) can be addressed by creating data filters, how you do this depends on whether your source is XML or ArrayCollection etc.
The first (uneditable row) will take some advanced itemrenderer programming and additional properties on your data to determine when a row should be uneditable.

This is not a simple case of 'disable row 5' - you're going to have to plan this through from a data point of view and create custom renderers to handle your specific requirements.

Can you provide more detail around your specific requirements?
0
 

Author Comment

by:ganands
Comment Utility
Thanks for your response!
Yes, you are right the control I am using is AdvancedDataGrid. The dataprovider for that is an Arraycollection.
One of the columns in the Arraycollection is a flag which determines whether that row should be editable or not. And this can change during run time based on user interaction. If this is complex coding then I would take it at a later point in time.
As far as making some rows invisible currently I am using 2 Arraycollections and deleting the rows that should not be displayed from one of the arraycollections, which is the dataprovider for the AdvancedDatagrid, and copying it back in to the Arraycollection (dataprovider) whenver it should be made invisible.  I ahve not used datafilter.
Thanks again for your support.
0
 
LVL 10

Accepted Solution

by:
mplord earned 250 total points
Comment Utility
OK one problem at a time: Data Filtering

With an ArrayCollection, you can set it's filterFunction property to point to a function of form 'fn(item:Object):Boolean' to return true or false as to whether to display that item or not.

Simple example is attached. As for specific data row enabled/disabled, that's a tricky question, could you raise another question for that? I will follow up.

If you want to ask any questions about how the data filter is setup please continue on this thread :)
<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init(event);">
 

	<mx:Script>

		<![CDATA[

			import mx.collections.ArrayCollection;

			

			[Bindable] public var datamodel:ArrayCollection = new ArrayCollection(); //space to hold our arraycollection data
 

			public function init(event:Event):void

			{

				// here just setting up data objects to be added to the arraycollection

				// these objects will be given the property 'age', which will be used in the filter

				// ideally these objects will be 'typed' to some specific class object, this is just a demo

				var obj1:Object = new Object();

				var obj2:Object = new Object();

				var obj3:Object = new Object();

				

				obj1['name'] = "Fred";

				obj1['age'] = "21";

				obj2['name'] = "Jim";

				obj2['age'] = "25";

				obj3['name'] = "Tom";

				obj3['age'] = "35";

				

				datamodel.addItem(obj1);

				datamodel.addItem(obj2);

				datamodel.addItem(obj3);

				

				// IMPORTANT PART

				// now set up the data filter

				datamodel.filterFunction = myFilter;

				datamodel.refresh(); //must call when setting a new filter

			}

			

			public function myFilter(item:Object):Boolean

			{

				// filter out items where age = 25;

				if (item['age'] == 25) return false;

				

				return true;

			}

			

		]]>

	</mx:Script>
 

	<mx:DataGrid id="myDataGrid" dataProvider="{datamodel}" horizontalCenter="0" verticalCenter="0" width="470" height="242">

		<mx:columns>

			<mx:DataGridColumn headerText="Name" dataField="name"/>

			<mx:DataGridColumn headerText="Age" dataField="age"/>

		</mx:columns>

	</mx:DataGrid>

	

</mx:Application>

Open in new window

0
 

Author Closing Comment

by:ganands
Comment Utility
Thanks again! I have change quite a bit to test the filter, which I will and let you know.  This solution would make things much easier.
0
 

Author Comment

by:ganands
Comment Utility
It is working fine for the rows invisible, but for me to make it visible again I need to process the arraycollection, but they are not available. I thought the filterfunction is only for the view purpose (ie. visibility in the datagrid, but it is fully available for processing from the Arraycollection point of view. Can you please clarify.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
Marketing can be an uncomfortable undertaking, especially if your material is technology based. Luckily, we’ve compiled some simple and (relatively) painless tips to put an end to your trepidation and start your path to success.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now