Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 829
  • Last Modified:

How to setproperty of a row in actionscript

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
ganands
Asked:
ganands
  • 3
  • 2
1 Solution
 
mplordCommented:
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
 
ganandsAuthor Commented:
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
 
mplordCommented:
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
 
ganandsAuthor Commented:
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
 
ganandsAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now