Hi Tracy,
Apologies but I am quite new with Flex.

Here are my codes:

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

                layout="vertical" backgroundGradientColors="[#FFCC00, #993300]" 
horizontalAlign="left">
    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.rpc.soap.mxml.WebService;
            import mx.managers.CursorManager;
            
            /**
             * @bindable 
             * @private
             * @property Will hold the data passed from the web service.
            */
            [Bindable]
            private var _xmlData:XML;
            
            private function clickHandler(event:MouseEvent) :void
            {
                CursorManager.setBusyCursor();
                event.target.enabled = false;
                
                var service:WebService = new WebService();
                
                service.addEventListener(ResultEvent.RESULT, 
serviceResultHandler);
                service.addEventListener(FaultEvent.FAULT, serviceFaultHandler);
                service.loadWSDL("http://localhost:55841/Service1.asmx?WSDL";);
                service.RetrieveSuppliers2();
            }
            
            private function serviceResultHandler(event:ResultEvent) :void
            {
                CursorManager.removeBusyCursor();
                _xmlData = XML(event.result);
                
                this.dataGrid.visible = true;
            }
            
            private function serviceFaultHandler(event:FaultEvent) :void
            {
                CursorManager.removeBusyCursor();
                Alert.show(String(event.fault), "Error");
                this.btnLoad.enabled = true;
            }
            
            private function getDataItems() :void
            {
                var intSelected:int;
                var strID:String;
                var strContactName:String;
                var strCompanyName:String;
                intSelected = dataGrid.selectedIndex;
                strID = dataGrid.selectedItem.ID;
                strCompanyName = dataGrid.selectedItem.CompanyName;
                
                txtID.text = strID;
                txtCompanyName.text = strCompanyName;
                
                //Alert.show(strCompanyName, intSelected.toString());
            }
            
            //private function sortNumericColumn(itemA:Object, itemB:Object): 
int
            //{
            //    return ObjectUtil.numericCompare(itemA[dataGrid.SupplierID], 
itemB[dataGrid.SupplierID]);
            //}
        ]]>
    </mx:Script>
    
    <mx:VBox horizontalCenter="0" 
             verticalCenter="0" 
             horizontalScrollPolicy="off"
             verticalScrollPolicy="off"
             height="100%"
             width="100%" >
        <mx:Button id="btnLoad" label="Load / Display Data" width="500" 
click="clickHandler(event);" />
        <mx:HDividedBox width="100%" height="100%">
            <mx:HBox width="70%" height="100%" borderStyle="solid">
                <mx:DataGrid id="dataGrid" width="100%" height="100%" 
visible="false" dataProvider="{_xmlData.*}" itemClick="getDataItems();">
                    <mx:columns>
                        <mx:DataGridColumn headerText="ID" 
dataField="SupplierID" width="30"/>
                        <mx:DataGridColumn headerText="Company Name" 
dataField="CompanyName" width="100"/>
                        <mx:DataGridColumn headerText="Contact Name" 
dataField="ContactName"  width="100"/>
                        <mx:DataGridColumn headerText="Contact Title" 
dataField="ContactTitle" width="50"/>
                        <mx:DataGridColumn headerText="Address" 
dataField="Address" width="150"/>
                    </mx:columns>
                </mx:DataGrid>
            </mx:HBox>
            <mx:HBox width="30%" height="100%" borderStyle="solid">
                <mx:Form id="frmDetails" label="Details">
                    <mx:FormItem direction="vertical" label="Company Name" 
required="true">
                        <mx:TextInput id="txtID" editable="false"/>
                        <mx:TextInput id="txtCompanyName" />
                        <mx:TextInput id="txtContactName" />
                        <mx:TextInput id="txtContactTitle" />
                        
                    </mx:FormItem>
                </mx:Form>
            </mx:HBox>
        </mx:HDividedBox>
    </mx:VBox>
</mx:Application>

In the code above, where do I place the resultFormat="e4x" which you specified?

Also, is there a way that instead of clicking a button, my datagrid would 
automatically retrieve during the start of the application (when I run the web 
page)?

I am trying slowly to work on techniques, gaining more firm understanding 
through simple application which am trying to build.
Thanks.






________________________________
From: Tracy Spratt <tr...@nts3rd.com>
To: flexcoders@yahoogroups.com
Sent: Thursday, 21 May, 2009 11:10:46
Subject: RE: [flexcoders] Re: modify item before binding to datagrid





Here is my advice:
        * Set resultFormat=”e4x”
        *  
        * In the result handler, loop over the xml nodes, for each, create and 
populate a VO class instance, taking care to get the data types correct
        * Put each VO in an ArrayCollection, 
        * Bind to the ArrayCollection
 
This will solve your sort issue, will
provide the most performant solution, and will allow for much more
functionality if needed.
 
 
Tracy Spratt,
Lariat Services, development services
available

________________________________
 
From:flexcod...@yahoogro ups.com [mailto: flexcod...@yahoogro ups.com ] On 
Behalf Of Angelo Anolin
Sent: Wednesday, May 20, 2009 9:46
AM
To: flexcod...@yahoogro ups.com
Subject: Re: [flexcoders] Re:
modify item before binding to datagrid
 




Hi Tracy,

Apologies if I am having a bit of a time trying to figure out what you said
here. 

My XML data is coming from a .NET webservice call, which is a dataset being
converted to XML and the value is being returned I believe as an XML string.

Now, when I bind the XML string to my datagrid, one of the columns is
originally numeric but since it was converted to string, when I sort the data,
it is not sorted numerically.

i.e. the Data is like:

1
2
3
4
...
10
11
...
20
21

when I click on the datagrid headers, the column is sorted like:
1
10
11
....
2
20
21

Is there any thing which I could do to override the sorting event of the
datagrid so that when the supposedly numeric column is sorted, it will be
sorted probably.

Thanks.
 

________________________________
 
From:Tracy
Spratt <tr...@nts3rd. com>
To: flexcod...@yahoogro ups.com
Sent: Tuesday, 19 May, 2009
9:52:16
Subject: RE: [flexcoders] Re:
modify item before binding to datagrid
If your data is changing type, I bet you have left the RPC data
service at its default resultFormat.  Set resultFormat=”e4x”
and adjust your dataProvider expression code accordingly.
 
DO use a result handler, do NOT bind directly to lastResult.
 
Tracy Spratt,
Lariat Services, development services available

________________________________
 
From:flexcod...@yahoogro ups.com [mailto:
flexcod...@yahoogro ups.com ] On Behalf Of markgoldin_2000
Sent: Monday, May 18, 2009 11:49
AM
To: flexcod...@yahoogro ups.com
Subject: [flexcoders] Re: modify
item before binding to datagrid
 



Sorry,
forgot to provide my sortable DataGrid:
package CustomComponents

{

import mx.collections. *;

import mx.controls. DataGrid;

import mx.controls. dataGridClasses. *;

import mx.events.DataGridE vent;

public class sortableDataGrid extends DataGrid

{

public function sortableDataGrid( )

{

super();

addEventListener( "headerRelease" , headerReleaseHeandl er);

}

public var sortIndex:int = -1;

public var sortColumn:DataGrid Column;

public var sortDirection: String;

public var lastSortIndex: int = -1;

public var col:String;

public function headerReleaseHeandl er(event: DataGridEvent) :void

{

col = columns[event. columnIndex] .dataField;

}

}

}

--- In flexcod...@yahoogro ups.com,
"markgoldin_ 2000" <markgoldin_ 2...@...> wrote:
>
> Here is what I am doing.
> column definition:
> <mx:DataGridColumn headerText=" Block"
dataField="tcbkcd" sortCompareFunction ="sortNumericCol
umnTrackTotal" />
> and:
> private function sortNumericColumnTr ackTotal( itemA:Object, itemB:Object)
:int
> {
> return ObjectUtil.numericC ompare(itemA[ TrackTotal. col],
itemB[TrackTotal. col]);
> } 
> 
> where TrackTotal is a DG's id.
> 
> HTH
> 
> --- In flexcod...@yahoogro ups.com,
Angelo Anolin <angelo_anolin@ > wrote:
> >
> > 
> > Hi.
> > 
> > I am quite new in Flex and would like to ask a simple question.
> > 
> > I am retrieving datasets from a .NET webservice and binding the same
to a datagrid. The datagrid comes with a feature that when you click on any of
the headers, the column is sorted ASC or DESC.
> > 
> > Now, one column which I am binding to is originally a numeric column.
But when it binds to the datagrid, it's data type becomes string. Is it
possible that prior to binding the said column to the datagrid, I would be able
to convert it back to its numeric data taype? Since sorting the column in a
string format would give a different result as compared to sorting the same
column in a numeric format.
> > 
> > Thanks.
> > 
> > Regards.
> >
>
 
   


      

Reply via email to