?
Solved

How to allow selective edit of rows in a Adobe FLEX 2 datagrid based on an XML defintion of which rows can be edited

Posted on 2008-06-16
4
Medium Priority
?
728 Views
Last Modified: 2008-06-17
Question on Adobe Flex Datagrid and XML:

We have a complex XML file which contains a definition of which fields can be edited on certain screens.  For example, we define Screen A consists of field 1, 2, 3.  Screen B consists of field 1,2,3,4,5,6,7 etc...  The field defintion includes the field name, whether it should be editable etc. and some other attributes.

We want to bind the list of screens defined in the XML file (e.g. A, B) to a drop-down list box and when the user selects an item, we want to bind the fields for that chosen screen to a datagrid.

Then, in the datagrid when the user clicks on a row, we want to say if the editable property defined for that field that has just been selected is editable = true then we want to allow the user to type in a value.  If the XML file for that Field defintion says editable = false then the users click on that row would be ignored.  Using the XML file will allow us to add fields or change their properties without having to recompile the application.

Any suggestions greatly appreciated.
0
Comment
Question by:STRATEGICAMS
[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
4 Comments
 
LVL 19

Expert Comment

by:Gary Benade
ID: 21800279
You can do it on a per column basis like this:
<mx:DataGridColumn editable="{@editable==true}"

Or on a per row basis by capturing the datagrids itemEditBeginning event and calling preventDefault() based on the contents of the event targets itemEditorInstance
0
 

Author Comment

by:STRATEGICAMS
ID: 21800914
hobbit72 could you elaborate a little as I can't quite understand how to implement this.  some examples / snippets would be extremely helpful if possible.
0
 
LVL 19

Accepted Solution

by:
Gary Benade earned 2000 total points
ID: 21801317
quick examples of both techniques.
In the first the columns are defined for the grid, in the second they are dynamically allocated based on the xml data
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
	<mx:Script>
		<![CDATA[
			import mx.controls.TextInput;
		
			[Bindable] private var myxml:XML = 
				<testdata>
					<datarow uid="1" foo="bar1" editable="true" />
					<datarow uid="2" foo="bar2" editable="false" />
					<datarow uid="3" foo="bar3" editable="true" />
				</testdata>;		
		]]>
	</mx:Script>
 	<mx:DataGrid id="dg" dataProvider="{myxml.datarow}" editable="true">
		<mx:columns>
	        <mx:DataGridColumn dataField="@uid" headerText="UID" width="85"/>
	        <mx:DataGridColumn dataField="@foo" headerText="FOO">
	        	<mx:itemEditor>	        		
			        <mx:Component>
			        	<mx:TextInput editable="{data.@editable==true}" />
			        </mx:Component>
	        	</mx:itemEditor>
	       	</mx:DataGridColumn>
	    </mx:columns> 		
 	</mx:DataGrid>
</mx:Application>

Open in new window

0
 
LVL 19

Assisted Solution

by:Gary Benade
Gary Benade earned 2000 total points
ID: 21801319

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
	<mx:Script>
		<![CDATA[
			import mx.events.DataGridEvent;
			import mx.controls.TextInput;
		
			[Bindable] private var myxml:XML = 
				<testdata>
					<datarow uid="1" foo="bar1" editable="true" />
					<datarow uid="2" foo="bar2" editable="false" />
					<datarow uid="3" foo="bar3" editable="true" />
				</testdata>;
			private function editBegin( e:DataGridEvent):void
			{
				var b:Boolean = e.itemRenderer.data.@editable == true; 
				if( b == false)
					e.preventDefault();
			}		
		]]>
	</mx:Script>
 	<mx:DataGrid id="dg" dataProvider="{myxml.datarow}" editable="true" itemEditBeginning="editBegin(event)"/>
</mx:Application>

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

762 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