[flexcoders] Re: Sort Column in a dynamically generated DataGrid using a Nested property

2008-04-29 Thread ben.clinkinbeard
You need to specify a custom sortCompareFunction for your
DataGridColumns that don't map directly to a property in your VO.

HTH,
Ben


--- In flexcoders@yahoogroups.com, sk_acura [EMAIL PROTECTED] wrote:

 Hi All,
 
   I have a DataGrid whose columns are generated at run time.
 
   In my MXML File it has only one Column and depending on the User
 Preference the Columns will be added to the Grid.
 
   Every thing is working fine except the sort won't work on columns as
 there is no variable with the column name in the Value Object. I have
 a Map in my Value object which contains the list of columns to be
 displayed..
 
   Here is my code..
 
 [CODE]
   for(var j:int=0;jpropertyCollection.length;j++){
   propertyNameTmp = propertyCollection[j];
   trace(Adding the Column =+propertyNameTmp+ To the Grid);
   var dgc:DataGridColumn = new DataGridColumn(propertyNameTmp);
   trace(Column DataField =+dgc.dataField);
   dgc.headerText= propertyNameTmp;
   dgc.labelFunction =getDataFieldValue;
   gridCols.push(dgc);
   }
   else{
   trace(No Need to add Column =+propertyHolder.propertyName+ 
 as it
 already Exists in the Grid);
   }
   }
 
  private function getDataFieldValue (node : Object, column :
 DataGridColumn) : String {
return node.propertyHolderMap[column.dataField];
 }
 [/CODE]
 
   Is there a function i can call to determine the field in the Value
 Object to use for figuring out how to sort the Columns ??
 
 Thanks
 Mars





[flexcoders] Re: Sort Column in a dynamically generated DataGrid using a Nested property

2008-04-29 Thread sk_acura
Hi Ben,

  Thanks for your reply..

  I added a custom sortable function and it looks like it fails when
it finds any null values !!

  The function i wrote is:

[CODE]

private function comparGridItem(itema:Node,itemb:Node):int{
var filteredField:String = selectedColumn;
trace(Selected Field =+filteredField);
var itemValueA:String = 
itema.propertyHolderMap[filteredField];
trace( Val1 =+itemValueA);
var itemValueB:String = 
itemb.propertyHolderMap[filteredField];
trace( Val2 =+itemValueB);
if(itemValueA!=null  itemValueB !=null){
if(itemValueA  itemValueB){
return -1;
}else if(itemValueA  itemValueB){
return 1;
}else{
return 0;
}
}
else{
if(itemValueA==null) return 1;
else return -1;
}
}

[/CODE]

 Does this mean if any of the Columns have null values it will throw
this Exception ??

Here is my output from the trace log..

[EXCEP]
Selected Field =namedisplay
 Val1 =Records Series A
 Val2 =Records Series B
Selected Field =namedisplay
 Val1 =Test Data
 Val2 =Records Series B

Error: Find criteria must contain at least one sort field value.
at mx.collections::Sort/findItem()
at mx.collections::ListCollectionView/getItemIndex()
at ListCollectionViewCursor/collectionEventHandler()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.collections::ListCollectionView/dispatchEvent()
at mx.collections::ListCollectionView/internalRefresh()
at mx.collections::ListCollectionView/refresh()
at mx.controls::DataGrid/sortByColumn()
at mx.controls::DataGrid/headerReleaseHandler()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()
at mx.controls::DataGrid/mouseUpHandler()
Error: Find criteria must contain at least one sort field value.
at mx.collections::Sort/findItem()
at mx.collections::ListCollectionView/getItemIndex()
at ListCollectionViewCursor/collectionEventHandler()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.collections::ListCollectionView/dispatchEvent()
at mx.collections::ListCollectionView/internalRefresh()
at mx.collections::ListCollectionView/refresh()
at mx.controls::DataGrid/sortByColumn()
at mx.controls::DataGrid/headerReleaseHandler()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()
at mx.controls::DataGrid/mouseUpHandler()
[/EXCEP]

Thanks
Mars