Solved

How to setproperty of a row in actionscript

Posted on 2009-05-16
5
778 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
ID: 24469597
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
ID: 24469665
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
ID: 24469814
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
ID: 31582307
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
ID: 24470158
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
FLEX 3 LineChart doubt 4 272
AS3 auto playing child movie clips? 2 628
learning partner 1 214
establish a .net -flex website with existing code 3 327
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…
Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

932 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

15 Experts available now in Live!

Get 1:1 Help Now