Go Back   CodingForums.com > :: Client side development > Flash & ActionScript > Adobe Flex

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-10-2009, 06:30 PM   PM User | #1
loki421
Regular Coder

 
Join Date: Feb 2009
Location: Worcester
Posts: 172
Thanks: 13
Thanked 6 Times in 6 Posts
loki421 is an unknown quantity at this point
Can I reorder a list in Flex and have it reflect in the db?

Hi all,

Bit of a tricky one here for me, let''s say i have a database with 5 entries, with a column called 'priority' which is set to numeric with values 1 - 5, and when i query the database i order them asc, ie:

Code:
<cfquery name="q" datasource="#dsn#">
SELECT priority
FROM myDataBase
ORDER BY priority asc
</cfquery>
I then show these items in a List control in Flex, now what i'm trying to do is develop something where i can reorder these in the database, ie changing the priority number.

I've tried using a drag and drop into another list control to reorder them, and that's fine visually, but how would i send that ordered list into the database?

Another thought i had was perhaps to have move up/down buttons, so that when an item is selected in the List control, it would grab the ID and priority from the database, then preform a calculation (don't know what) to +/- 1 from the priority, but it's a bit much for me to work out on my own, and also how would the others in the database get re-arranged?

Does anyone here have any experiance with this sort of thing or could someone point me in the right direction for a good tutorial on something simular? Any help would be gratefully appreciated!

Many thanks in advance all!

Last edited by loki421; 06-10-2009 at 06:32 PM..
loki421 is offline   Reply With Quote
Old 06-11-2009, 11:56 AM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Here is an example of how you might do it:
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
	<mx:Script>
		<![CDATA[
			import mx.controls.Alert;
		
			private function updateDB():void
			{
				var temp:String = '';
				for(var i:String in itemList.dataProvider)
					temp += itemList.dataProvider[i].data + '\n';

				Alert.show(temp);
			}
		]]>
	</mx:Script>

	<mx:List id="itemList"
		dragEnabled="true" 
		dragMoveEnabled="true" 
		dropEnabled="true">
		<mx:ArrayCollection>
			<mx:Object label="Item 1" data="1" />
			<mx:Object label="Item 2" data="2" />
			<mx:Object label="Item 3" data="3" />
			<mx:Object label="Item 4" data="4" />
			<mx:Object label="Item 5" data="5" />
			<mx:Object label="Item 6" data="6" />
		</mx:ArrayCollection>
	</mx:List>
	<mx:Spacer height="30" />
	<mx:Button label="Update"
		click="updateDB()" />
</mx:Application>
I used an ArrayCollection for the data provider, but you could easily adapt this to work with your database/RemoteObject source.
Inigoesdr is offline   Reply With Quote
Old 06-11-2009, 01:41 PM   PM User | #3
loki421
Regular Coder

 
Join Date: Feb 2009
Location: Worcester
Posts: 172
Thanks: 13
Thanked 6 Times in 6 Posts
loki421 is an unknown quantity at this point
That's awesome dude! Love how it works and keeps the order, the thing is i need to send that order back to the db and have it change the 'position' column in the relevant row, so if i moved recordID number 1 with a position of 1, to position 2 in the list, it needs to know that ID 1's position has changed to 2 and to update the database accordingly, do you think this is possible?

Great work by the way!!!
loki421 is offline   Reply With Quote
Old 06-12-2009, 06:34 PM   PM User | #4
loki421
Regular Coder

 
Join Date: Feb 2009
Location: Worcester
Posts: 172
Thanks: 13
Thanked 6 Times in 6 Posts
loki421 is an unknown quantity at this point
I'm still not having any joy with this, i can't seem to be able to break the string down into seperate numbers that i can pass back to the database to reflect the change...... Can anyone suggest a way this might be done? It won't let me use a Number value

(Or i'm just doing it completely wrong! )

Thanks in advance anyone!
loki421 is offline   Reply With Quote
Old 06-12-2009, 10:08 PM   PM User | #5
loki421
Regular Coder

 
Join Date: Feb 2009
Location: Worcester
Posts: 172
Thanks: 13
Thanked 6 Times in 6 Posts
loki421 is an unknown quantity at this point
Ok, i think i might be getting somewhere here, i think if i could get the rowIndex of this list, then if i drag and drop an item at the top it's row index should remain at 1 right? If so then all i have to do is send the rowIndex back along with the recordID??? I think.....
loki421 is offline   Reply With Quote
Old 06-13-2009, 07:07 PM   PM User | #6
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Ah, I should have clarified that a bit more. In my example the ArrayCollection was acting as the database, so the "data" field I used would be the "recordID" for your case. To update your database you could send back a delimited, ordered list that you get by looping through the dataProvider, and use the recordID to update the row. An example might be:
Code:
<cfset numlist="4,2,1,3,5"> <!--- this is your list of the order from flex --->
<cfset order=1>
<cfloop index="num" list="#numlist#">
        <cfquery datasource="#myDSN#">
            UPDATE mytable SET order= #order# WHERE id = #num#
        </cfquery>
    <cfset order++>
</cfloop>
This code has not been tested, it's just an example off the top of my head(CF is not my forte).
Inigoesdr is offline   Reply With Quote
Users who have thanked Inigoesdr for this post:
loki421 (06-14-2009)
Old 06-14-2009, 03:40 AM   PM User | #7
loki421
Regular Coder

 
Join Date: Feb 2009
Location: Worcester
Posts: 172
Thanks: 13
Thanked 6 Times in 6 Posts
loki421 is an unknown quantity at this point
Of course!! A delimited list! Dude you are a star I'll have a play with this but i'm pretty sure you're right. You rock! lol

Oh, love the avatar by the way, one of my fav films... 'Hello, my name is Inigo Montoya, you killed my father, prepare to die' Awesome!!

Once again thaks for this, you've been such a great help

Peace
loki421 is offline   Reply With Quote
Old 09-08-2011, 09:18 AM   PM User | #8
salma66
New to the CF scene

 
Join Date: Sep 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
salma66 is an unknown quantity at this point
Believe or not, but this thread helped me even now, after so much time
So thanks a million!!!
salma66 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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


All times are GMT +1. The time now is 09:23 PM.


Advertisement
Log in to turn off these ads.