Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Flex > Flex 2, 3 & 4

Reply
 
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
Old 04-09-2008, 04:24 PM   #1
skinnyFlash
Registered User
 
Join Date: Jun 2007
Posts: 32
Default dataGrid - dynamically change order of columns

I'm trying to dynamically reset the order of columns in my dataGrid. I thought it would be as simple as changing columnIndex but can't find anything about how to make that work.

What I have is a list component that is populated by all of the dataGrid column/header names. I have to allow the user to re-order the header/column names within the list component > click ok/done > and then have the datagrid columns re-ordered as specified.

Is there something simple (like columnIndex) that I'm missing or do I have to somehow re-organize my array and re-populate the dataGrid?

Any help greatly appreciated!!
skinnyFlash is offline   Reply With Quote
Old 04-09-2008, 09:23 PM   #2
kahuja
Maverick
 
kahuja's Avatar
 
Join Date: Mar 2008
Location: India
Posts: 225
Send a message via AIM to kahuja Send a message via Yahoo to kahuja
Default

You would need to swap the columns, which are added to the grid.
__________________
Happy Flexing !!
k.

Scratch Pad
kahuja is offline   Reply With Quote
Old 04-09-2008, 10:07 PM   #3
skinnyFlash
Registered User
 
Join Date: Jun 2007
Posts: 32
Default

Hi Kahuja,
Thanks for the reply.
I actually have another question if you'd be so kind.
I'm using PopUpManager to create a dialog box that conains a List. What I need to do is take the contents of the List and turn it into an array that I can then use in the main application. I'm having trouble reading the array once back in the main app.

Let me know if you require to the code.

Thanks in advance!!
skinnyFlash is offline   Reply With Quote
Old 04-09-2008, 10:10 PM   #4
kahuja
Maverick
 
kahuja's Avatar
 
Join Date: Mar 2008
Location: India
Posts: 225
Send a message via AIM to kahuja Send a message via Yahoo to kahuja
Default

Use the MVC architecture; when you make an array, bind that to a Model (singleton implementation) and then use that in the application.

I am making certain assumptions on the problem you are facing, in case this is not the case, please explain your problem.
__________________
Happy Flexing !!
k.

Scratch Pad
kahuja is offline   Reply With Quote
Old 04-09-2008, 11:44 PM   #5
skinnyFlash
Registered User
 
Join Date: Jun 2007
Posts: 32
Default

Great!
Things are working out over here...finally!!
Thanks again.
skinnyFlash is offline   Reply With Quote
Old 04-10-2008, 03:42 AM   #6
kahuja
Maverick
 
kahuja's Avatar
 
Join Date: Mar 2008
Location: India
Posts: 225
Send a message via AIM to kahuja Send a message via Yahoo to kahuja
Default

Good to hear, enjoy Flexing!!
__________________
Happy Flexing !!
k.

Scratch Pad
kahuja is offline   Reply With Quote
Old 04-10-2008, 08:31 PM   #7
skinnyFlash
Registered User
 
Join Date: Jun 2007
Posts: 32
Default

Unfortunately I wasn't as successful as I thought at dynamically changing the order of my dataGrid columns and now I'm in desperate need of help. Below I've included a very simplified bit of code and if anyone out there could make it so that the button included in the code simply swaped the positions of the two columns I would be greatful! When the "Toggle Columns" button is pressed I need the column (and its rows) "Name" to swap places with the column "Account":
Code:
<?xml version="1.0"?>
<!-- dpcontrols/DataGridValidateNowSelindex.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
   initialize="initData();">

   <mx:Script>
       <![CDATA[
    
            import mx.collections.ArrayCollection;

            [Bindable]
            private var DGArray:ArrayCollection = new ArrayCollection([
                {Account:'Lorem', Name:'Albert'},
                {Account:'Lorem Ipsum', Name:'Ben'}]);
         
            // Initialize initDG ArrayCollection variable from the ArrayCollection.
            public function initData():void {
                myGrid.dataProvider = DGArray;
                myGrid.validateNow();
                //myGrid.selectedIndex=1;
            }
        ]]>
   </mx:Script>

   <mx:DataGrid id="myGrid" sortableColumns="true" lockedColumnCount="0"
            horizontalScrollPolicy="on" height="200" width="400">
      <mx:columns>
         <mx:DataGridColumn dataField="Account" id="account"/>
         <mx:DataGridColumn dataField="Name" id="tname"/>
      </mx:columns> 
   </mx:DataGrid>

   <mx:Button label="Toggle Columns" click="account.visible = !account.visible;" />
</mx:Application>
I will be extremely greatful is someone could help with this!

Thanks in advance!
skinnyFlash is offline   Reply With Quote
Old 04-11-2008, 04:52 PM   #8
kahuja
Maverick
 
kahuja's Avatar
 
Join Date: Mar 2008
Location: India
Posts: 225
Send a message via AIM to kahuja Send a message via Yahoo to kahuja
Default

Just to be clear, are you looking at a code that swaps the columns?
__________________
Happy Flexing !!
k.

Scratch Pad
kahuja is offline   Reply With Quote
Old 04-11-2008, 05:17 PM   #9
skinnyFlash
Registered User
 
Join Date: Jun 2007
Posts: 32
Default

I have nothing in place that has successfully worked so the answer is no. What I'm pretty sure needs to happen at this point is that I need to dynamically create the DataGridColumns with an array so that with the click of a button I can re-order the array and then re-create the DataGridColumns with the re-ordered array (not sure). It seems simple enough but I can't find out how to dynamically create the DataGridColumns. I've been working on this for days and I feel like I'm going in circles! The code I included in my last post (as you can tell) is just a dataGrid with a button and my hope was someone would re-post the code with a working example (of swapping columns using the button) for me to work from. I of course would love any type of help with this though!
skinnyFlash is offline   Reply With Quote
Old 04-11-2008, 09:25 PM   #10
skinnyFlash
Registered User
 
Join Date: Jun 2007
Posts: 32
Default

I finally got something to work (not the best way I'm sure)...now I have to assign an ID number to each dataGrid column name within the array some how. You'll see in the application that when you click on the List entries the dataGrid swaps its colmuns depending on which list name you click on. My goal at this point is to make it so that the user can rearrange (drag and drop) the names that are displayed in the List component and the dataGrid's column names will re-arrange accordingly. Any ideas?
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
        	import mx.collections.ArrayCollection;
        	
            [Bindable]private var arrayOfString:Array;
            [Bindable]private var nIDOne:Number = 0;
            [Bindable]private var nIDTwo:Number = 1;
            private var arrayOfObject:Array;
            
            [Bindable]
            public var DGArray:ArrayCollection = new ArrayCollection([
                {Artist:'Jack', Price:'Lots'},
                {Artist:'Jill', Price:'None'}
            ]);

            private function init():void {
                arrayOfString = ["Artist", "Price"];
                
                myGrid.dataProvider = DGArray;
                myGrid.validateNow();
            }
            
            private function swapColumns():void {
				if(tReturn.selectedItem == "Artist"){
					nIDOne = 0;
					nIDTwo = 1;
				}else if(tReturn.selectedItem == "Price"){
					nIDOne = 1;
					nIDTwo = 0;
				}
            	init();
			}

        ]]>
    </mx:Script>
            
    <mx:DataGrid id="myGrid" initialize="init();"> 
        <mx:columns>
            <mx:DataGridColumn dataField="{arrayOfString[nIDOne]}" />
            <mx:DataGridColumn dataField="{arrayOfString[nIDTwo]}" />
        </mx:columns>
    </mx:DataGrid>
    <!--<mx:Button label="Swap Columns" click="swapColumns()" />-->
    
      <mx:List  
	    id="tReturn"
	 	dataProvider ="{arrayOfString}"
	    allowMultipleSelection="true" 
	    labelField="dataField"               
	    dragEnabled="true"
	    dropEnabled="true"
	    dragMoveEnabled="true"
	    click="swapColumns()"
	  />
	
	<mx:Label text="Selected (index values): {tReturn.selectedIndex}  "/>
	<!--<mx:Button label="Swap Columns" click="swapColumns()"/>-->

</mx:Application>
Any input or help is extremely welcome and will be much appreciated!

Thanks!
skinnyFlash is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to dynamically change line color? drexle ActionScript 2.0 1 03-19-2008 02:15 PM
How can i change the default Sort Arrow Color in the datagrid? takiz Flex 2, 3 & 4 1 11-24-2007 02:35 AM
possible to dynamically change the depth property of a layer? opivy1017 ActionScript 2.0 7 05-24-2006 03:40 AM
tab order with dynamically loaded swfs? tweaknee ActionScript 1.0 (and below) 0 04-07-2005 01:16 AM
DataGrid and limiting columns jkemrich Components 1 12-30-2003 07:00 PM


All times are GMT. The time now is 11:39 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.