PDA

View Full Version : Trouble with datagrid


Anitha
04-10-2008, 11:41 AM
Hi everyone, I need help with my datagrid and service call. I have two datagrids.
The first datagrid is populated by a webservice result
[fields : year,projected,achieved] .
The second datagrid is for when a year is selected from the first datagrid
the second datagrid is populated by another one service [fields :year,division,projected,achieved].
Everything is ok.Here I need to get the year value from first grid and pass it when i invoke the data service method call to get the particular year status.At this end I met some problem.

Here is my code. [Sorry for long such code]. i hope this helps.

If someone could help me please, I would really appreciate .

Thanks in advance
Anitha


[Bindable]
public var secondgridanswer:Array;
[Bindable]
public var answer:ArrayCollection=new ArrayCollection;


private function getDivisiondetails(event:Object):void
{
var a:Number=event.target.selectedItem.year;
myservice.getDivision.send(a);
}


private function onResult(event:Object):void
{
// assigns the result to the dataProvider variable
var secondgridanswer:Array=event.result as Array;
// simulated result
secondgridanswer=simulateResult(event);
}

private function simulateResult(event:Object):Array
{
var a:Number=event.target.selectedItem.year;
var divisiondetail:Array=new Array(); //temporary array

//whole devisiondetail array
var divisiondetailall:Array=myservice.getDivision;

//loop through all the records
for(var i:Number=0;i<divisiondetailall.length;i++)
var obj:Object =divisiondetailall[i];

///find any that matches the currently selected record
if (obj.year==a)
{
divisiondetail.push(obj); // add it to the temp array
}
return divisiondetail; // return the temp array
}
]]>



<mx:DataGrid x="60" y="132" dataProvider="{answer}" id="firstgrid" change="getDivisiondetails(event)">
<mx:columns>
<mx:Array>
<mx:DataGridColumn headerText="year" dataField="year"/>
<mx:DataGridColumn headerText="projected" dataField="projected"/>
<mx:DataGridColumn headerText="achieved" dataField="achieved"/>
</mx:Array>
</mx:columns>
</mx:DataGrid>


<mx:DataGrid id="secondgrid" x="314" y="337" dataProvider="{secondgridanswer}">
<mx:columns>
<mx:Array>
<mx:DataGridColumn headerText="year" dataField="year"/>
<mx:DataGridColumn headerText="division" dataField="division"/>
<mx:DataGridColumn headerText="projected" dataField="projected"/>
<mx:DataGridColumn headerText="achieved" dataField="achieved"/>
</mx:Array>
</mx:columns>
</mx:DataGrid>


<mx:WebService id="myservice" wsdl="http://localhost/Service.asmx?wsdl"
showBusyCursor="true"
fault="mx.controls.Alert.show(event.fault.faultString);">
<mx:operation name="getSelectionPeriod" resultFormat="object"
fault="mx.controls.Alert.show(event.fault.faultString);"
result="remotingHandler(event)">
<mx:request xmlns="">
<Fromyear>{fy.selectedDate.getFullYear()}</Fromyear>
<Toyear>{ty.selectedDate.getFullYear()}</Toyear>
</mx:request>
</mx:operation>

<mx:operation name="getDivision" resultFormat="object"
result="onResult(event)">
</mx:operation>
</mx:webservice>

kahuja
04-10-2008, 01:43 PM
You said "some" problem, can you please be more specific.

Anitha
04-11-2008, 05:56 AM
Hi,
When i click the year in my firstgrid ,it shows the error report,""Property selectedItem not found on mx.rpc.soap.mxml.operation and there is no default value"".As a newbie i cant identify this problem.Here ism using flex3

kahuja
04-11-2008, 09:03 AM
Try not using the event's property but the grid directly. I did something as:
gridArtifactListing.selectedItem

Not the best approach, but works.

Anitha
04-11-2008, 10:07 AM
Wow! i got answer.Thanks kahuja.But i cant find what is the mistake in my last method
Anyway thanks for reply and also sorry for thread.

kahuja
04-11-2008, 12:15 PM
Have fun. :-)