...

DataGrid Sort

DevilRay
09-18-2011, 06:00 AM
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.

Inigoesdr
09-18-2011, 08:55 PM
Add a callback to the sortChange event on your datagrid and then call ensureCellIsVisible() to force a scroll to the top:
<?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>

DevilRay
09-18-2011, 11:11 PM
This is exactly what I was looking for. It works perfectly. Thanks! I really appreciate it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum