Sorting Datagrid
argh, frustrating!
Is it really possible that I cant sort a datagrid with script
when user presses the button.
Lets say datagrid have three columns. Col 1, col 2 and col 3.
I have three buttons that lead user to the datagrid and each
of them should sort the datagrid by the column user clicked
(equivalent button)?
Just sort the underlying collection. Assuming your using an
arrayCollection
do the following:
userList.source.sortOn(["org","name"]);
This is a collection of user objects where I sort by org and
name.
Then either reset the grids dataprovider or send out a
Collection changed event:
var c:CollectionEvent = new
CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
userList.dispatchEvent(c)
Similar Messages
-
How not to sort datagrid column on double click
Hello,
I am currently building an application containing a datagrid for data representation. I've created a custom datagridheader in order to add a input text for filtering the columns (see code below).
My goal is to hide the textinput, and then show it on a double click on the header. So i would like to know how to avoid the sort of this column each time i double click.?
<?xml version="1.0" encoding="utf-8"?>
<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" resize="onColumnResize(event)" clipAndEnableScrolling="true" doubleClick="managefilterField(event)">
<fx:Declarations>
<!--- The default value of the <code>sortIndicator</code> property.
It must be an IFactory for an IVisualElement.
<p>This value is specified in a <code>fx:Declaration</code> block and can be overridden
by a declaration with <code>id="defaultSortIndicator"</code>
in an MXML subclass.</p>
@langversion 3.0
@playerversion Flash 10
@playerversion AIR 2.0
@productversion Flex 4.5
-->
<fx:Component id="defaultSortIndicator">
<s:Path data="M 3.5 7.0 L 0.0 0.0 L 7.0 0.0 L 3.5 7.0" implements="spark.components.gridClasses.IGridVisualElement">
<fx:Script>
<![CDATA[
import spark.components.DataGrid;
import spark.components.Grid;
* @private
public function prepareGridVisualElement(grid:Grid, rowIndex:int, columnIndex:int):void
const dataGrid:DataGrid = grid.dataGrid;
if (!dataGrid)
return;
const color:uint = dataGrid.getStyle("symbolColor");
arrowFill1.color = color;
arrowFill2.color = color;
]]>
</fx:Script>
<s:fill>
<s:RadialGradient rotation="90" focalPointRatio="1">
<!--- @private -->
<s:GradientEntry id="arrowFill1" color="0" alpha="0.6" />
<!--- @private -->
<s:GradientEntry id="arrowFill2" color="0" alpha="0.8" />
</s:RadialGradient>
</s:fill>
</s:Path>
</fx:Component>
<!--- Displays the renderer's label property, which is set to the column's <code>headerText</code>.
It must be an instance of a <code>TextBase</code>, like <code>s:Label</code>.
<p>This visual element is added to the <code>labelDisplayGroup</code> by the renderer's
<code>prepare()</code> method. Any size/location constraints specified by the labelDisplay
define its location relative to the labelDisplayGroup.</p>
<p>This value is specified with a <code>fx:Declaration</code> and can be overridden
by a declaration with <code>id="labelDisplay"</code>
in an MXML subclass.</p>
@langversion 3.0
@playerversion Flash 10
@playerversion AIR 2.0
@productversion Flex 4.5
-->
<s:Label id="labelDisplay"
verticalCenter="1" left="0" right="0" top="0" bottom="0"
textAlign="start"
fontWeight="bold"
verticalAlign="middle"
maxDisplayedLines="1"
showTruncationTip="true" />
</fx:Declarations>
<fx:Script>
<![CDATA[
import net.awl.ismp.console.components.misc.FilterCriteria;
import net.awl.ismp.console.events.ColumnFilteredEvent;
import net.awl.ismp.console.events.ColumnResizedEvent;
import mx.events.ResizeEvent;
import spark.components.gridClasses.IGridVisualElement;
import mx.core.IVisualElement;
import spark.components.DataGrid;
import spark.components.GridColumnHeaderGroup;
import spark.components.gridClasses.GridColumn;
import spark.primitives.supportClasses.GraphicElement;
// chrome color constants and variables
private static const DEFAULT_COLOR_VALUE:uint = 0xCC;
private static const DEFAULT_COLOR:uint = 0xCCCCCC;
private static const DEFAULT_SYMBOL_COLOR:uint = 0x000000;
private static var colorTransform:ColorTransform = new ColorTransform();
* @private
private function dispatchChangeEvent(type:String):void
if (hasEventListener(type))
dispatchEvent(new Event(type));
protected function onColumnResize(event:ResizeEvent):void
dispatchEvent(new ColumnResizedEvent(ColumnResizedEvent.COLUMNRESIZED_EVT,this.width,this.column.columnInde x));
// maxDisplayedLines
private var _maxDisplayedLines:int = 1;
[Bindable("maxDisplayedLinesChanged")]
[Inspectable(minValue="-1")]
* The value of this property is used to initialize the
* <code>maxDisplayedLines</code> property of this renderer's
* <code>labelDisplay</code> element.
* @copy spark.components.supportClasses.TextBase#maxDisplayedLines
* @default 1
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 1.5
* @productversion Flex 4.5
public function get maxDisplayedLines():int
return _maxDisplayedLines;
override protected function stateChanged(oldState:String, newState:String, recursive:Boolean):void
trace("state changed from : "+oldState+" to "+newState);
super.stateChanged(oldState, newState, recursive);
* @private
public function set maxDisplayedLines(value:int):void
if (value == _maxDisplayedLines)
return;
_maxDisplayedLines = value;
if (labelDisplay)
labelDisplay.maxDisplayedLines = value;
invalidateSize();
invalidateDisplayList();
dispatchChangeEvent("maxDisplayedLinesChanged");
// sortIndicator
private var _sortIndicator:IFactory;
private var sortIndicatorInstance:IVisualElement;
[Bindable("sortIndicatorChanged")]
* A visual element that's displayed when the column is sorted.
* <p>The sortIndicator visual element is added to the <code>sortIndicatorGroup</code>
* by this renderer's <code>prepare()</code> method. Any size/location constraints
* specified by the sortIndicator define its location relative to the sortIndicatorGroup.</p>
* @default null
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 1.5
* @productversion Flex 4.5
public function get sortIndicator():IFactory
return (_sortIndicator) ? _sortIndicator : defaultSortIndicator;
* @private
public function set sortIndicator(value:IFactory):void
trace("setSortIndicator");
if (_sortIndicator == value)
return;
_sortIndicator = value;
if (sortIndicatorInstance)
sortIndicatorGroup.includeInLayout = false;
sortIndicatorGroup.removeElement(sortIndicatorInstance);
sortIndicatorInstance = null;
invalidateDisplayList();
dispatchChangeEvent("sortIndicatorChanged");
* @private
* Create and add the sortIndicator to the sortIndicatorGroup and the
* labelDisplay into the labelDisplayGroup.
override public function prepare(hasBeenRecycled:Boolean):void
trace("prepare !!");
super.prepare(hasBeenRecycled);
if (labelDisplay && labelDisplayGroup && (labelDisplay.parent != labelDisplayGroup))
labelDisplayGroup.removeAllElements();
labelDisplayGroup.addElement(labelDisplay);
trace(sortIndicator);
trace("sortIndicatorInstance : "+sortIndicatorInstance);
const column:GridColumn = this.column;
if (sortIndicator && column && column.grid && column.grid.dataGrid && column.grid.dataGrid.columnHeaderGroup)
const dataGrid:DataGrid = column.grid.dataGrid;
const columnHeaderGroup:GridColumnHeaderGroup = dataGrid.columnHeaderGroup;
if (columnHeaderGroup.isSortIndicatorVisible(column.columnIndex))
if (!sortIndicatorInstance)
sortIndicatorInstance = sortIndicator.newInstance();
sortIndicatorGroup.addElement(sortIndicatorInstance);
chromeColorChanged = true;
invalidateDisplayList();
// Initialize sortIndicator
sortIndicatorInstance.visible = true;
const gridVisualElement:IGridVisualElement = sortIndicatorInstance as IGridVisualElement;
if (gridVisualElement)
gridVisualElement.prepareGridVisualElement(column.grid, -1, column.columnIndex);
sortIndicatorGroup.includeInLayout = true;
sortIndicatorGroup.scaleY = (column.sortDescending) ? 1 : -1;
else
if (sortIndicatorInstance)
sortIndicatorGroup.removeElement(sortIndicatorInstance);
sortIndicatorGroup.includeInLayout = false;
sortIndicatorInstance = null;
private var chromeColorChanged:Boolean = false;
private var colorized:Boolean = false;
* @private
* Apply chromeColor style.
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
//trace("update display list");
// Apply chrome color
if (chromeColorChanged)
var chromeColor:uint = getStyle("chromeColor");
if (chromeColor != DEFAULT_COLOR || colorized)
colorTransform.redOffset = ((chromeColor & (0xFF << 16)) >> 16) - DEFAULT_COLOR_VALUE;
colorTransform.greenOffset = ((chromeColor & (0xFF << 8)) >> 8) - DEFAULT_COLOR_VALUE;
colorTransform.blueOffset = (chromeColor & 0xFF) - DEFAULT_COLOR_VALUE;
colorTransform.alphaMultiplier = alpha;
transform.colorTransform = colorTransform;
var exclusions:Array = [labelDisplay, sortIndicatorInstance];
// Apply inverse colorizing to exclusions
if (exclusions && exclusions.length > 0)
colorTransform.redOffset = -colorTransform.redOffset;
colorTransform.greenOffset = -colorTransform.greenOffset;
colorTransform.blueOffset = -colorTransform.blueOffset;
for (var i:int = 0; i < exclusions.length; i++)
var exclusionObject:Object = exclusions[i];
if (exclusionObject &&
(exclusionObject is DisplayObject ||
exclusionObject is GraphicElement))
colorTransform.alphaMultiplier = exclusionObject.alpha;
exclusionObject.transform.colorTransform = colorTransform;
colorized = true;
chromeColorChanged = false;
super.updateDisplayList(unscaledWidth, unscaledHeight);
* @private
override public function styleChanged(styleProp:String):void
var allStyles:Boolean = !styleProp || styleProp == "styleName";
super.styleChanged(styleProp);
if (allStyles || styleProp == "chromeColor")
chromeColorChanged = true;
invalidateDisplayList();
protected function managefilterField(event:MouseEvent):void
trace("double click sortIndicator : "+this.sortIndicatorInstance);
this.filterInput.visible=!this.filterInput.visible;
this.filterInput.includeInLayout=this.filterInput.visible;
this.filterSpacer.visible=this.filterInput.visible;
this.filterSpacer.includeInLayout=this.filterInput.visible;
if(!this.filterInput.visible)
this.filterInput.text="";
dispatchEvent(new ColumnFilteredEvent(ColumnFilteredEvent.COLUMNFILTERED_EVT,new FilterCriteria(this.column.dataField,this.filterInput.text)));
this.filterInput.setStyle("borderColor",0xFF6319);
this.filterInput.setStyle("focusColor",0xFF6319);
//this.filterInput.setStyle(
protected function onTextInputSelection(event:MouseEvent):void
event.stopImmediatePropagation();
this.filterInput.setStyle("borderColor",0xFF6319);
this.filterInput.setStyle("focusColor",0xFF6319);
protected function onKeyUp(event:KeyboardEvent):void
if(event.charCode==Keyboard.ENTER)
stage.focus=null;
protected function onFocusOut(event:FocusEvent):void
this.filterInput.setStyle("borderColor",0x00ff00);
this.filterInput.setStyle("focusColor",0x70B2EE);
dispatchEvent(new ColumnFilteredEvent(ColumnFilteredEvent.COLUMNFILTERED_EVT,new FilterCriteria(this.column.dataField,this.filterInput.text)));
]]>
</fx:Script>
<s:states>
<s:State name="normal" />
<s:State name="hovered" />
<s:State name="down" />
</s:states>
<!-- layer 1: shadow -->
<!--- @private -->
<s:Rect id="shadow" left="-1" right="-1" top="-1" bottom="-1" radiusX="2">
<s:fill>
<s:LinearGradient rotation="90">
<s:GradientEntry color="0x000000"
color.down="0xFFFFFF"
alpha="0.01"
alpha.down="0" />
<s:GradientEntry color="0x000000"
color.down="0xFFFFFF"
alpha="0.07"
alpha.down="0.5" />
</s:LinearGradient>
</s:fill>
</s:Rect>
<!-- layer 2: fill -->
<!--- @private -->
<s:Rect id="fill" left="0" right="0" top="0" bottom="0">
<s:fill>
<s:LinearGradient rotation="90">
<s:GradientEntry color="0xFFFFFF"
color.hovered="0xBBBDBD"
color.down="0xAAAAAA"
alpha="0.85" />
<s:GradientEntry color="0xD8D8D8"
color.hovered="0x9FA0A1"
color.down="0x929496"
alpha="0.85" />
</s:LinearGradient>
</s:fill>
</s:Rect>
<!-- layer 3: fill lowlight -->
<!--- @private -->
<s:Rect id="lowlight" left="0" right="0" top="0" bottom="0">
<s:fill>
<s:LinearGradient rotation="270">
<s:GradientEntry color="0x000000" ratio="0.0" alpha="0.0627" />
<s:GradientEntry color="0x000000" ratio="0.48" alpha="0.0099" />
<s:GradientEntry color="0x000000" ratio="0.48001" alpha="0" />
</s:LinearGradient>
</s:fill>
</s:Rect>
<!-- layer 4: fill highlight -->
<!--- @private -->
<s:Rect id="highlight" left="0" right="0" top="0" bottom="0">
<s:fill>
<s:LinearGradient rotation="90">
<s:GradientEntry color="0xFFFFFF"
ratio="0.0"
alpha="0.33"
alpha.hovered="0.22"
alpha.down="0.12"/>
<s:GradientEntry color="0xFFFFFF"
ratio="0.48"
alpha="0.33"
alpha.hovered="0.22"
alpha.down="0.12" />
<s:GradientEntry color="0xFFFFFF"
ratio="0.48001"
alpha="0" />
</s:LinearGradient>
</s:fill>
</s:Rect>
<!-- layer 5: highlight stroke (all states except down) -->
<!--- @private -->
<s:Rect id="highlightStroke" left="0" right="0" top="0" bottom="0" excludeFrom="down">
<s:stroke>
<s:LinearGradientStroke rotation="90" weight="1">
<s:GradientEntry color="0xFFFFFF" alpha.hovered="0.22" />
<s:GradientEntry color="0xD8D8D8" alpha.hovered="0.22" />
</s:LinearGradientStroke>
</s:stroke>
</s:Rect>
<!-- layer 6: highlight stroke (down state only) -->
<!--- @private -->
<s:Rect id="hldownstroke1" left="0" right="0" top="0" bottom="0" includeIn="down">
<s:stroke>
<s:LinearGradientStroke rotation="90" weight="1">
<s:GradientEntry color="0x000000" alpha="0.25" ratio="0.0" />
<s:GradientEntry color="0x000000" alpha="0.25" ratio="0.001" />
<s:GradientEntry color="0x000000" alpha="0.07" ratio="0.0011" />
<s:GradientEntry color="0x000000" alpha="0.07" ratio="0.965" />
<s:GradientEntry color="0x000000" alpha="0.00" ratio="0.9651" />
</s:LinearGradientStroke>
</s:stroke>
</s:Rect>
<!--- @private -->
<s:Rect id="hldownstroke2" left="1" right="1" top="1" bottom="1" includeIn="down">
<s:stroke>
<s:LinearGradientStroke rotation="90" weight="1">
<s:GradientEntry color="0x000000" alpha="0.09" ratio="0.0" />
<s:GradientEntry color="0x000000" alpha="0.00" ratio="0.0001" />
</s:LinearGradientStroke>
</s:stroke>
</s:Rect>
<!--<s:Rect id="fill" left="0" right="0" top="0" bottom="0">
<s:fill>
<s:LinearGradient rotation="90">
<s:GradientEntry color.normal="0xf9f9f9" color.hovered="0xfcfdfa"
color.down="0xdceac2" alpha="0.85" />
<s:GradientEntry color.normal="0xeaeaea" color.hovered="0xdceac2"
color.down="0xd2e1b5" alpha="0.85" />
</s:LinearGradient>
</s:fill>
</s:Rect>-->
<!--<s:VGroup left="7" right="7" top="5" bottom="5" gap="6" verticalAlign="middle">
<s:TextInput width="100%" />
<s:HGroup width="100%">
<s:Group id="labelDisplayGroup" width="100%" />
<s:Group id="sortIndicatorGroup" includeInLayout="false" />
</s:HGroup>
</s:VGroup>-->
<s:VGroup verticalAlign="middle" left="7" top="5" right="7" bottom="5" gap="2" >
<s:TextInput id="filterInput" width="100%" visible="false" includeInLayout="false" keyUp="onKeyUp(event)" focusOut="onFocusOut(event)" click="onTextInputSelection(event)"/>
<s:Spacer id="filterSpacer" visible="false" includeInLayout="false" height="5" />
<s:HGroup width="100%" height="100%" verticalAlign="middle">
<s:Group id="labelDisplayGroup" width="100%" />
<s:Group id="sortIndicatorGroup" includeInLayout="false" />
</s:HGroup>
</s:VGroup>
</s:GridItemRenderer>Based on your idea, i've intercepted the click event and I use stopImmediatePropagation.
THen i added an image to sort the column. So if the image is clicked the sort is ok. -
Strange application behaviour after try to sort datagrid column
Hi all
I have a simple Air desktop application with customized DataGrid (Spark version). Problem that users found is when they trying to sort grid by one of the columns applicaiton closes without any messages. I've repeated this bug on my PC but there is a problem - in debug mode (i mean with ADL) it works OK without any tries to crash on sort. So my questions in priority order:
1. Is that possible to obtain live Air application errors log? I mean after installation. Maybe with 3rd party applicaiton. I'm using MonsterDebugger and added few log messages but looks like application just crashes without firing closing or close event.
2. Which part of DataGrid could crash applicaiton in release mode? Just thought debug mode is more strict.
My dev system:
Flash Builder 4.6
Adobe Air 3.2
Win 7 Ultimate 64bit
Best regards, Roman
P.S. Sorry for my bad englishBased on your idea, i've intercepted the click event and I use stopImmediatePropagation.
THen i added an image to sort the column. So if the image is clicked the sort is ok. -
Sort datagrid column in groupby
Hai
can any one help to sort the advanced datagrid column in ascending
by default the values will be in groupby format..
how to sort in groupby...
Thanks in AdvanceHai
can any one help to sort the advanced datagrid column in ascending
by default the values will be in groupby format..
how to sort in groupby...
Thanks in Advance -
Sort DataGrid with dataprovider XMLisCollection
I can't get my datagrid to sort when I have a
XMLListcollection as the dataprovider and I have to use a
labelfunction to get the records to display because of the
namespace in the XML (Replicating a .NET web service).
Can someone help, Please?
I have the following code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="vertical" creationComplete="initApp()" >
<mx:Script>
<![CDATA[
import mx.controls.dataGridClasses.DataGridColumn;
import mx.controls.DataGrid;
import mx.events.DataGridEvent;
import mx.collections.*;
import mx.controls.Alert;
import mx.formatters.DateFormatter;
//the dataProvider for the DG
[Bindable]
private var _xlc:XMLListCollection;
[Bindable]
private var sortA:Sort;
// The sort fields used to determine the sort.
private var sortBySeverity:SortField;
private var sortByRequestor:SortField;
public function initApp():void
namespace myNameS = "myNamespace.Test";
use namespace myNameS;
_xlc = new
XMLListCollection(GetRequestList.*..SafRequestListVO);
//testing element values
trace(GetRequestList.*..SafRequestListVO.SeverityLevel);
sortA = new Sort();
sortBySeverity = new SortField("SeverityLevel", true, true);
sortByRequestor = new SortField("Requestor", true);
sortA.fields=[sortBySeverity, sortByRequestor];
_xlc.sort=sortA;
_xlc.refresh();
dg.dataProvider = _xlc;
dg.rowCount=_xlc.length +1;
/**labelFunction to return data to DG by reference of
dataField*/
private function LF(item:Object,
column:DataGridColumn):Object
namespace myNameS = "myNamespace.Test";
use namespace myNameS;
var colDataField:Object = column.dataField;
switch (colDataField) //logic to determine which node to get
the data from
case "SAFNumber":
return item.SAFNumber;
break;
case "RequestDate":
var date:String = new String(item.RequestDate).toString();
var df:DateFormatter = new DateFormatter();
df.formatString = "YYYY-MM-DD";
return df.format(date);
break;
case "SeverityLevel":
return item.SeverityLevel;
break;
case "Requestor":
return item.Requestor;
break;
case "IssuedToDepartment":
return item.IssuedToDepartment;
break;
default:
return item.dataField;
break;
]]></mx:Script>
<mx:Canvas id="datagridParent" borderStyle="solid"
height="450" width="100%" >
<mx:DataGrid id="dg" width="100%" height="100%"
rowCount="5" labelFunction="LF">
<mx:columns>
<mx:DataGridColumn dataField="SAFNumber"
headerText="SAFNumber"/>
<mx:DataGridColumn dataField="Requestor"
headerText="Requestor"/>
<mx:DataGridColumn dataField="RequestDate"
headerText="RequestDate"/>
<mx:DataGridColumn dataField="IssuedToDepartment"
headerText="IssuedToDepartment"/>
<mx:DataGridColumn dataField="SeverityLevel"
headerText="SeverityLevel"/>
</mx:columns>
</mx:DataGrid>
</mx:Canvas>
<mx:XML id="GetRequestList" format="e4x">
<GetRequestListResponse xmlns="myNamespace.Test">
<GetRequestListResult>
<SafRequestListVO>
<RequestGuid>3F2504E0-4F89-11D3-9A0C-0305E82C3301</RequestGuid>
<SAFNumber>1</SAFNumber>
<RequestDate>03/24/2007</RequestDate>
<Requestor>Michael</Requestor>
<IssuedToDepartment>1</IssuedToDepartment>
<IssuedToArea>3</IssuedToArea>
<IssuedByDepartment>string</IssuedByDepartment>
<Problem>Problem Details........Problem
Details........</Problem>
<SeverityLevel>3</SeverityLevel>
<CurrentState>string</CurrentState>
</SafRequestListVO>
<SafRequestListVO>
<RequestGuid>3F2504E0-4F89-11D3-9A0C-0305E82C3302</RequestGuid>
<SAFNumber>2</SAFNumber>
<RequestDate>02/21/2006</RequestDate>
<Requestor>Bill</Requestor>
<IssuedToDepartment>1</IssuedToDepartment>
<IssuedToArea>2</IssuedToArea>
<IssuedByDepartment>string</IssuedByDepartment>
<Problem>Problem Details........Problem
Details........Problem Details........Problem
Details........Problem Details........</Problem>
<SeverityLevel>1</SeverityLevel>
<CurrentState>string</CurrentState>
</SafRequestListVO>
<SafRequestListVO>
<RequestGuid>3F2504E0-4F89-11D3-9A0C-0305E82C3303</RequestGuid>
<SAFNumber>3</SAFNumber>
<RequestDate>01/06/2007</RequestDate>
<Requestor>Jonathan</Requestor>
<IssuedToDepartment>8</IssuedToDepartment>
<IssuedToArea>2</IssuedToArea>
<IssuedByDepartment>string</IssuedByDepartment>
<Problem>string</Problem>
<SeverityLevel>1</SeverityLevel>
<CurrentState>string</CurrentState>
</SafRequestListVO>
<SafRequestListVO>
<RequestGuid>3F2504E0-4F89-11D3-9A0C-0305E82C3304</RequestGuid>
<SAFNumber>4</SAFNumber>
<RequestDate>03/27/2007</RequestDate>
<Requestor>Bill</Requestor>
<IssuedToDepartment>7</IssuedToDepartment>
<IssuedToArea>2</IssuedToArea>
<IssuedByDepartment>string</IssuedByDepartment>
<Problem>Problem Details........Problem
Details........Problem Details........Problem
Details........Problem Details........</Problem>
<SeverityLevel>3</SeverityLevel>
<CurrentState>string</CurrentState>
</SafRequestListVO>
<SafRequestListVO>
<RequestGuid>3F2504E0-4F89-11D3-9A0C-0305E82C3305</RequestGuid>
<SAFNumber>5</SAFNumber>
<RequestDate>12/21/2006</RequestDate>
<Requestor>Mike</Requestor>
<IssuedToDepartment>4</IssuedToDepartment>
<IssuedToArea>2</IssuedToArea>
<IssuedByDepartment>string</IssuedByDepartment>
<Problem>string</Problem>
<SeverityLevel>2</SeverityLevel>
<CurrentState>string</CurrentState>
</SafRequestListVO>
<SafRequestListVO>
<RequestGuid>3F2504E0-4F89-11D3-9A0C-0305E82C3306</RequestGuid>
<SAFNumber>6</SAFNumber>
<RequestDate>04/02/2007</RequestDate>
<Requestor>Nick</Requestor>
<IssuedToDepartment>2</IssuedToDepartment>
<IssuedToArea>2</IssuedToArea>
<IssuedByDepartment>string</IssuedByDepartment>
<Problem>Problem Details........Problem
Details........Problem Details........Problem
Details........Problem Details........</Problem>
<SeverityLevel>3</SeverityLevel>
<CurrentState>string</CurrentState>
</SafRequestListVO>
<SafRequestListVO>
<RequestGuid>3F2504E0-4F89-11D3-9A0C-0305E82C3307</RequestGuid>
<SAFNumber>7</SAFNumber>
<RequestDate>03/27/2007</RequestDate>
<Requestor>Sandeep</Requestor>
<IssuedToDepartment>4</IssuedToDepartment>
<IssuedToArea>2</IssuedToArea>
<IssuedByDepartment>string</IssuedByDepartment>
<Problem>Problem Details........Problem
Details........Problem Details........Problem
Details........</Problem>
<SeverityLevel>2</SeverityLevel>
<CurrentState>string</CurrentState>
</SafRequestListVO>
</GetRequestListResult>
</GetRequestListResponse>
</mx:XML>
</mx:Application>Michael, I am sorry, but I myself have significant difficulty
with xml namespaces. I have managed to get some examples working
but only by trial and error and studying up on Namespace in the
docs.
http://www.cflex.net/showfiledetails.cfm?ChannelID=1&Object=File&objectID=582
I am just not good enough with them to be able to tell you
what you need to do.
Tracy -
Sort DataGrid Numerically?
I want to sort numbers numerically (like "1, 3, 10") rather
than alphabetically ("1, 10, 3" ). Everything I've found uses
ActionScript work-arounds on the underlying dataprovider. But
surely I'm missing something and there's an easier way.
Right?First, make sure your data is in fact numbers and not a
string with numerials in it. This is one of those things I can't
seem to keep in my head, so you'll need to experiment first. If
that doesn't work (I think it will), then you need to create a Sort
and a SortItem. The Sort is added to the dataProvider collection,
not to the DataGrid. -
I have a DataGrid with several columns and I would like to be
able to sort it with a ComboBox. So if option a in the comboBox is
selected then column A in the DataGrid will be used to sort. I
option B is selected then a different column wil sort the DataGrid.
How would I go about this?
Thanks
Dave"dmschenk" <[email protected]> wrote in
message
news:gbe16o$c4p$[email protected]..
> I have a DataGrid with several columns and I would like
to be able to sort
> it
> with a ComboBox. So if option a in the comboBox is
selected then column A
> in
> the DataGrid will be used to sort. I option B is
selected then a
> different
> column wil sort the DataGrid. How would I go about this?
I think there's an example of this at
http://blog.flexexamples.com -
Hi,
I am using flex datagrid to develop an application in french,
as french is having special character in it,
i need to sort datagrid column in french. Flex datagrid
unable to sort data in french. i need french sorting,
if somebody has solution of this please help me to get out of
this.
If possible please reply me on
[email protected]i am using inbuilt flex sorting, i am not using sortcompare()
function.
its just a string sorting but as its in french ,character
"
É" is comig after character "
V" , because flex treated it as a special character
. it should come before "
V". so do we need to change character set for
flex? -
DataGrid Moving rows up and down
I have this function to move rows up in a datagrid , yet i am having problems when it comes to move to rows down. I have tried changing the following line to +1 but it dint work any hints please.
ac.addItemAt(itemToShift,dg.selectedIndex-1);
This is the code
public function up():void
if(dg.selectedIndex == -1)
Alert.show("Select the row which you want to up.");
return;
if(dg.selectedIndex == 0)return;
var selectedRowInx : Number = dg.selectedIndex;
var itemToShift : Object = ac.getItemAt(selectedRowInx) as Object;
ac.addItemAt(itemToShift,dg.selectedIndex-1);
ac.removeItemAt(dg.selectedIndex);
dg.invalidateDisplayList();Okay. So, I made the code a little simpler than what I said. With my code, you could have selected a row, clicked a cut button, then selected a another row to past afterwards or whatever. Here is the code for simply moving the row up and down.
I added code to catch if the row was at the top or the bottom of the data. Also, I created two indexes, one for the grid and one for the array collection. It will probably work with the one index, but I was trying to see if I could do the move on a sorted datagrid, but that is basically pointless.
protected function moveUpBtn_clickHandler(event:MouseEvent):void
var upSelectedIndex:int = myDataGrid.selectedIndex;
// Move Item
if(upSelectedIndex > -1) {
if(upSelectedIndex > 0) {
// Get the selected Object
var moveObject:Object = myArrayCollection.getItemAt(upSelectedIndex);
// Get actual Object location if grid is sorted
var upActualIndex:int = myArrayCollection.getItemIndex(moveObject);
// Remove selected item at actualIndex
myArrayCollection.removeItemAt(upActualIndex);
myArrayCollection.refresh();
// Move both indexes
upActualIndex--;
upSelectedIndex--;
// insert item at actualIndex
myDataGrid.dataProvider.addItemAt(moveObject, upActualIndex);
myArrayCollection.refresh();
// select grid at selectedIndex
myDataGrid.selectedIndex = upSelectedIndex;
} else {
Alert.show("Item is currently at the top of the list.", "Move Alert", Alert.OK, this);
} else {
Alert.show("No Item Selected.", "Move Alert", Alert.OK, this);
protected function moveDownBtn_clickHandler(event:MouseEvent):void
var downSelectedIndex:int = myDataGrid.selectedIndex;
if(downSelectedIndex > -1) {
// Move Item
if(downSelectedIndex < myArrayCollection.length -1) {
// Get the selected Object
var moveObject:Object = myArrayCollection.getItemAt(downSelectedIndex);
// Get actual Object location if grid is sorted
var downActualIndex:int = myArrayCollection.getItemIndex(moveObject);
// Remove selected item at actualIndex
myArrayCollection.removeItemAt(downActualIndex);
myArrayCollection.refresh();
// Move both indexes
downActualIndex++;
downSelectedIndex++;
// insert item at actualIndex
myDataGrid.dataProvider.addItemAt(moveObject, downActualIndex);
myArrayCollection.refresh();
// select grid at selectedIndex
myDataGrid.selectedIndex = downSelectedIndex;
} else {
Alert.show("Item is currently at the bottom of the list.", "Move Alert", Alert.OK, this);
} else {
Alert.show("No Item Selected.", "Move Alert", Alert.OK, this);
Here is the blog post with the working DataGrid and Source View
Message was edited by: DeanLoganBH - Had to set the Down Move to look for the Length of the ArrayCollection -1, because the DataGrid row starts at 0, it is one less than the total length of the ArrayCollection. -
Custom Sort (by date) in a DataGrid component
So I've got a data grid component hooked up to a data provider like so:
var weekData:XML=// some xml loaded in earlier....
var weekGrid:DataGrid=new DataGrid();
var dataProvider:DataProvider=new DataProvider();
for each(var entry:XML in weekData){
dp.addItem({event:entry.title,date:FormatDate.format(new Date(entry.@startDate),5),data:entry.@startDate});
The title column is just what you might think. The date colum is actually a format like May 2012 or Feb 2013. And the data "column" isn't actually shown in the dataGrid it is the "key" for sorting by date. It contains the getTime() value of the date like 1328515200000. So that will make date sorting just a case of Array.NUMERIC with the appropriate Array.DESCENDING when needed.
I've found that if I do this:
weekGrid.dataProvider.sortOn("data",Array.NUMERIC)
weekGrid.invalidate();
it works and the grid is sorted -- IF I have some other button to click to cause that code to run.
I want to tie it together with the click event on the grid header. Thusly:
weekGrid.addEventListener(DataGridEvent.HEADER_RELEASE,sortDataGrid);
And I've getting the event and all, but evidently that is fireing off the built-in sorting which happens after mine. And it doesn't do what I want.
Any idea how to stop that and allow my perferred sorting to take place?if you don't want the user to sort your datagrid, use:
weekGrid.sortableColumns = false;
and execute your sort without clicking anything. or use:
weekGrid.addEventListener(DataGridEvent.HEADER_RELEASE,sortDataGrid);
function sortDataGrid(e:DataGridEvent):void{
setTimeout(sortF,100);
function sortF():void{
weekGrid.dataProvider.sortOn("data",Array.NUMERIC) -
How do i know when a datagrid has been sorted?
i can figure out what/how a datagrid has been sorted but i can't seem to catch *when* it's been sorted. there's no "sort" event, headerRelease is happening before the sort and CollectionEvent & DataChange aren't firing when sorted. left scratching my head.
any suggestions?
thanks.thanks alex, building the test case helped me work out the issue (i think).
test case has creationComplete that builds dummy data ArrayCollection (bindable), refreshes the datagrid dataprovider, then adds the eventListener. if i put the addEventListener call before any of this, it gets ignored.
in the real app, the data is coming in via coldfusion (cf) remoting calls. i was adding the eventListener before any data was returned, guess i'll have to work out something in the result handlers.
timing bits my ankles off again ;-)
thanks for the help. -
Keep sorting and sort arrows after datagrid dbprovider changed
I followed this tutorial http://justinjmoses.wordpress.com/2008/06/26/flex-keeping-the-sort-on-a-datagrid-when-you- change-the-dataprovider/
created listeners
that keeps old sorting of datagrid after dataprovider changed, but displaying sort arrow on the wrong column(always the 1st column), how do I fix it?
//constructor
public function FilterDatagrid()
super();
addEventListener(mx.events.CollectionEvent.COLLECTION_CHANGE, onDataGridDataChange, false, 0, true);
private var currentSort:mx.collections.Sort;
private function onDataGridDataChange(evt:CollectionEvent):void
//get the new data collection
var ac:ArrayCollection = this.dataProvider as ArrayCollection;
//attach the collection change event
ac.addEventListener(CollectionEvent.COLLECTION_CHANGE, onCollectionChanged,false,0,true);
//if a sort was in place before the data was changed, make sure you apply the sort to this new data
if (currentSort != null)
ac.sort = currentSort;
ac.refresh();
private function onCollectionChanged(evt:CollectionEvent):void
if (evt.kind == CollectionEventKind.REFRESH)
var ac:ArrayCollection = evt.currentTarget as ArrayCollection;
currentSort = ac.sort;the datagrid uses XML as dataprovider and uses labelFunction and sortCompareFunction on each column, not sure if it matters
-
Add sort images in DataGrid Header
Hi,
I have a datagrid, where in I have defined the 'headerRelease' event to sort the data-grid columns. The sorting that I have to use is not the default sorting. It has some other rules, which have been defined in the headerRelease event.
<mx:DataGrid id="idGridWebAlerts" dataProvider="{ webAlertsPage }" variableRowHeight="true"
width="100%" headerRelease="headRelEvt(event)" selectable="false" />
In the headerRelease method, I have called the preventDefault() method of the header Release event, which will disable the default sorting. Due to this method call, the sort order images, that appear by default on datagrid column header do not show up.
One of the ways to add those images is to use HeaderRenderers, but that causes flickering of headers after the datagrid has loaded. Is there any other way we can get/add the sort order depiction images to data grid header?
Please help.
AnjaliHi,
I tried the table sorter utility.but it is sorting only if there are text property.
so it is sorting according to the text.
then i tried the code
Comparator comparator = new Comparator()
public int compare(Object x1, Object x2)
IResultNodeElement e1 = (IResultNodeElement ) x1;
IResultNodeElement e2 = (IResultNodeElement ) x2;
return e1.getDs().compareTo(e2.getDs());
wdContext.nodeResultNode().sortElements(comparator);
Then it is sorting in one order..is there any way to sort it in other order..
Regards
AD -
Editable DataGrid won't sort correctly
This is the weirdest behavior I've ever seen...
I am working on a datagrid (editable="true"), and for some reason the thing does not want to sort correctly. It is a basic datagrid with itemrenderers for each column so that we can edit in the grid. Sorting should happen on a header-click, but if you click the header, it seems to simply select the first row, or another random row, and doesn't sort. It does fire the "itemEditEnd" event. However, if you click anywhere but the header, drag the mouse to header and then let go, (mouseUp on the header), then it sorts perfectly fine (and doesn't fire that event). If I take the "editable=true" off the datagrid, it sorts fine on header-clicks, but then the datagrid won't save.
Does anyone have any ideas? There isn't any custom behavior on the header, though I could add some if it would help. I've tried everything I can think of, but nothing seems to help.
This seems to be somewhat related to this (unsolved) issue.
http://bugs.adobe.com/jira/browse/SDK-18302
Thanks,I have noticed in the livedocs under, "Working with item renderers" (currently as I type this post the livedocs is unavailable, so I am able to give you a URL) there is a Datagrid that functions incorrectly when the user clicks on header columns. I am not sure why they haven't fixed this yet, but is this similar to what you are experiencing? I believe on the same page, they mention about the differences with creationComplete and dataChange. Are you listening to any of those events? creationComplete is rarely used in an itemrenderer. dataChange is used more often which I have noticed that a conditional statement is needed to prevent strange behavior (perhaps the same as you mentioned).
-
Hi all,
We are running one query from Sql Query Analyser ,
for selecting values and displaying it in ascending order.
We are executing the same query from coding to load in to
datagrid , but its not arranging it by ascending order instead
its sorting randomly.
Because of this, if i select particular row from Datagrid, its not fetching
the selected row from the grid instead its taking corresponding row number's
value.
Thanks
VaithyHI vaitheeswaran l... ,
yeah what u said is correct grid takes in that manner when u are using collapse levels.try without using collapse levels.if u want using collapse levels it wont come
Edited by: micheal willis on Oct 9, 2009 11:34 AM
Maybe you are looking for
-
Web link to PDF loads as gibberish
Link works fine on PC's. With a Mac the link shows as gibberish when the page loads. However clicking anywhere in the address field of Safari and reloading the page (pressing enter) loads the pdf just fine. Verified that the latest AdobePDFViewer.plu
-
Does Apple Mail have a "return receipt" feature similar to Outlook?
Does Apple Mail have a "return receipt" feature similar to Outlook?
-
Not sure where to ask this. I just wanted to know when approximately they release new versions of the touch? I realize no info about new ones has been released but I am trying to get an estimate as to when the others were released and when we might e
-
Centering a .swf file HELP°!
When I have created a .flv file with a .html file from Indesign, and i open the .html file. Everything that i made works fine But! the flash file ( the actual Site) is always on the Left of the browser. ! I really need some help as i know absolutely
-
After setting the db to archive log mode what to do?
Hi All, We have a database which is being used as production database since one week and running in NoArchive Log mode. Now i wanted to change that to Archive Log mode because i want to take hot backup using RMAN daily/weekly. My doubt is..after chan