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 09-18-2011, 06:00 AM   PM User | #1
DevilRay
New to the CF scene

 
Join Date: Sep 2011
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
DevilRay is an unknown quantity at this point
DataGrid Sort

The default behavior of the Flex datagrid descending sort seems to be that a selected row remains in view, meaning that the view will scroll down to show the selected row. I would like to change this so that when doing a descending sort the view remains at the top instead of scrolling. I'm new to Flex, so if someone could give me an example, I would appreciate it, with either DataGrid or AdvancedDataGrid. Thanks.
DevilRay is offline   Reply With Quote
Old 09-18-2011, 08:55 PM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,602
Thanks: 2
Thanked 398 Times in 391 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Add a callback to the sortChange event on your datagrid and then call ensureCellIsVisible() to force a scroll to the top:
Code:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
			   xmlns:s="library://ns.adobe.com/flex/spark"
			   xmlns:mx="library://ns.adobe.com/flex/mx"
			   width="300" height="300">
	<fx:Script>
		<![CDATA[
			import spark.events.GridSortEvent;
						
			protected function myDG_sortChangeHandler(event:GridSortEvent):void
			{
				myDG.ensureCellIsVisible(0);
			}			
		]]>
	</fx:Script>
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
	
	<s:DataGrid id="myDG" width="250" height="250" sortChange="myDG_sortChangeHandler(event)">
		<s:columns>
			<s:ArrayList>
				<s:GridColumn dataField="@label" headerText="Label" />
				<s:GridColumn dataField="@data" headerText="Data" />
			</s:ArrayList>
		</s:columns>
		<s:dataProvider>
			<s:XMLListCollection id="dp">
				<s:source>
					<fx:XMLList>
						<product label="Product 1" data="3" />
						<product label="Product 2" data="1" />
						<product label="Product 3" data="4" />
						<product label="Product 4" data="1" />
						<product label="Product 5" data="5" />
						<product label="Product 6" data="9" />
						<product label="Product 1" data="3" />
						<product label="Product 2" data="1" />
						<product label="Product 3" data="4" />
						<product label="Product 4" data="1" />
						<product label="Product 5" data="5" />
						<product label="Product 6" data="9" />
					</fx:XMLList>
				</s:source>
			</s:XMLListCollection>
		</s:dataProvider>
	</s:DataGrid>
	
</s:Application>
Inigoesdr is offline   Reply With Quote
Users who have thanked Inigoesdr for this post:
DevilRay (09-18-2011)
Old 09-18-2011, 11:11 PM   PM User | #3
DevilRay
New to the CF scene

 
Join Date: Sep 2011
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
DevilRay is an unknown quantity at this point
This is exactly what I was looking for. It works perfectly. Thanks! I really appreciate it.
DevilRay 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 10:46 PM.


Advertisement
Log in to turn off these ads.