function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ktdsmktdsm 

Problem in Populating AdvanceDataGrid in Flex 3 - Salesforce

I am populating advanceDataGrid (Flex 3) from salesforce query. I want to show parent-child relationship in the grid.

The problem is that, when i am iterating the queryresult object in the for loop and dumping in the arraycollection object, it only adds those records into the Array , that has chidren in it.Otherwise , it is exiting the loop.

for example , if first record has a child then, it adds it into the array collection object  and goes to second iteration i.e i=1.When it sees that second parent record doesn't have any child in it then it exist the loop and bind the advance datagrid with only one record.Although , the queryresult has 8 parent rows in it.
When i apply this check around the addition process of records into the arraycollection object :

 

if(qr.records[k].RecS__Features__r != null){

}

 

After applying the above if {} check ,it starts adding the rows in it but only those rows that has Children.But it didn't show the children records in the Grid.Now it shows only Parent Records without children .

I need to display those   Records that don't have any Children as well as those that have Children associated to it in the advance datagrid.So that , the rows with children records , user can expand the node to see its children.With rows no folder sign , the user will come to know that this row doesn't have any child rows.

Here is my code :

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"

xmlns:salesforce="http://www.salesforce.com/" applicationComplete="init()"

themeColor="#E7ECEF" cornerRadius="3">

 

<salesforce:Connection id="force" />

 

<mx:Script >

<![CDATA[

 //import statements here

 

//Declaration

[Bindable]

private var objSprint:Object;

[Bindable]private var gdSprint:ArrayCollection=new ArrayCollection();
[Bindable]

private var tempSprint:ArrayCollection=new ArrayCollection();

 

 

 //Code here

private function init():void

{

var lr:LoginRequest = new LoginRequest(); lr.username = "salesforce username";
lr.password =
"************";
lr.callback = new AsyncResponder(loginHandler);

force.login(lr);

 

lr.callback = new AsyncResponder(populateGrid);

force.login(lr);

}

 

 

private function loginHandler(result:LoginResult):void

{

 

force.query("Select id ,Name,RecS__Product_Name__c from RecS__Product_Backlog__c ",

new AsyncResponder(function(result:QueryResult):void

{

 

 

ddlBack.addItemAt("All",0);

 

for(var i : int =0 ; i < result.records.length;i++){

 

ddlBack.addItem({Id:result.records[i].Id,RecS__Product_Name__c :result.records[i].RecS__Product_Name__c,SObjectField:result.records[i]});

 

 

}

 

}));

 

}

 

private function populateGrid(result:LoginResult):void{

 

force.query("Select r.Id, r.Name,r.RecS__Sprint_Name__c, r.RecS__Start_Date__c, r.RecS__Status__c, (Select Id,"+

" Name, "RecS__Feature_Name__c, RecS__Product_Backlog__c,  RecS__Sprint__c, RecS__Start_Date__c  From "+ 

"RecS__Features__r where RecS__Product_Backlog__c =null "+

" and RecS__Sprint__c <> null) from RecS__Sprint__c r",new AsyncResponder(function(qrSp:QueryResult):void

{

gdSprint=qrSp.records;

 

for(var k:int =0 ; k < qrSp.records.length ; k++)

{

lbl.text+= qrSp.records[k].RecS__Features__r.records.length; 

if(qrSp.records[k].RecS__Features__r != null){
tempSprint.addItem({RecS__Sprint_Name__c :qrSp.records[k].RecS__Sprint_Name__c,

Id:qrSp.records[k].Id,Children:qrSp.records[k].RecS__Features__r.records,SObjectField:qrSp.records[k]});
}
}

objSprint =Object(tempSprint);

 gridSprint.dataProvider=tempSprint; 

 

}));

}

  

]]>

</mx:Script>
<mx:Panel title="Sprint Items"  

paddingTop="10" paddingLeft="10" paddingRight="10" height="554" width="505" x="416" y="44">

<mx:AdvancedDataGrid id="gridSprint" designViewDataType="tree" width="419" height="451">

<mx:dataProvider> 

<mx:HierarchicalData source="{objSprint}" childrenField="Children" > </mx:HierarchicalData>

</mx:dataProvider> 

<mx:columns>

<mx:AdvancedDataGridColumn headerText="Sprint" fontStyle="normal" fontWeight="bold" dataField="RecS__Sprint_Name__c">

 </mx:AdvancedDataGridColumn> <mx:AdvancedDataGridColumn headerText="Feature" dataField="RecS__Feature_Name__c"/>

<mx:AdvancedDataGridColumn headerText="St. Date" dataField="RecS__Start_Date__c"/>

<mx:AdvancedDataGridColumn headerText="Id" visible="false" dataField="Id"/>

</mx:columns> 

</mx:AdvancedDataGrid>

</mx:Panel>

</mx:Application>

 

Please can any one help me ... it is driving me crazy ....