Solved

How to setproperty of a row in actionscript

Posted on 2009-05-16
5
788 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
flex4 : css styles 1 499
AS3 parent function 3 692
ComboBox ItemRenderer inside Datagrid 2 1,099
FlashBuilder allocate more memory using FlashBuilder.ini 18 299
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…
The goal of this blog is to: > note what has impeded us from reaching effective life on-call > provide 3 steps to mastering life on-call > highlight what will be achieved with effective life on-call
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

710 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