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

Similar Messages

  • Sort DataGrid with ComboBox

    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

  • Problem with selectedItem (DataGrid) when dataProvider is XML

    I have a problem.
    I want to load my DataGrid with data from XML returned via
    Struts. I have set up a test environment for the time being and I
    can LOAD the data into the grid just fine, but when I want to refer
    to it after it is loaded (with selectedItem) I am having all sorts
    of problems. Namely, I can't access any of the data in
    selectedItem. I can't even seem to make it show up in a string...
    the only way I can access values is individually using :
    selectedItem["@attribute"] which is NOT what I want to do...
    can anyone tell me what I am doing wrong? Is there no way I
    can convert the xml to an object (or is that even the problem)?
    Here is code to show exactly what I mean:
    <?xml version="1.0"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="vertical" creationComplete="doDummySearch()">
    <mx:Script>
    <![CDATA[
    import mx.utils.ArrayUtil;
    import mx.controls.Alert;
    //this dummyXML is in place of the response from the server
    for now...
    private var dummyXML:XML =
    <root>
    <dummyData priority='0' dealerCode='A00-1023'
    phoneNo='0343442323' />
    <dummyData priority='1' dealerCode='B00-1033'
    phoneNo='0343442323' />
    <dummyData priority='0' dealerCode='DER-0666'
    phoneNo='0343442323' />
    </root>
    private function doDummySearch():void {
    search_dg.dataProvider = dummyXML.children();
    private function select():void {
    var s:String = "";
    s+=search_dg.selectedItem["@dealerCode"]+"\n";
    s+="all data: \n";
    for each (var entry:* in search_dg.selectedItem) {
    s+=entry+"\n";
    s+="^-why is this blank?\n";
    s+="selectedItem.toString():
    "+search_dg.selectedItem.toString()+" <-why is this blank?";
    mx.controls.Alert.show(s, "selected data:");
    ]]>
    </mx:Script>
    <mx:DataGrid id="search_dg" />
    <mx:Button label="select item" click="select()" />
    </mx:Application>

    Or even better, you can use the new E4X support in Flex, to
    directly read from the XML
    See this example
    main.xml
    <?xml version="1.0"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    xmlns="*" layout="vertical" >
    <mx:Script>
    <![CDATA[
    private function select():void {
    var s:String = "";
    s+="Symbol = "+search_dg.selectedItem.Symbol+"\n";
    s+="Quantity = "+search_dg.selectedItem.Quantity+"\n";
    s+="Price = "+search_dg.selectedItem.Price+"\n";
    s+="Value = "+search_dg.selectedItem.Value+"\n";
    mx.controls.Alert.show(s, "selected data:");
    ]]>
    </mx:Script>
    <mx:XML format="e4x" id="portfolioModel"
    source="portfolio.xml" />
    <mx:DataGrid id="search_dg"
    dataProvider="{portfolioModel.security}">
    <mx:columns>
    <mx:DataGridColumn dataField="Symbol"
    headerText="Symbol"/>
    <mx:DataGridColumn dataField="Quantity"
    headerText="Quantity"/>
    <mx:DataGridColumn dataField="Price"
    headerText="Price"/>
    <mx:DataGridColumn dataField="Value"
    headerText="Value"/>
    </mx:columns>
    </mx:DataGrid>
    <mx:Button label="select item" click="select()" />
    </mx:Application>
    portfolio.xml
    <portfolio>
    <security>
    <Symbol>MSFT</Symbol>
    <Quantity>10000</Quantity>
    <Price>20.56</Price>
    <Value>1</Value>
    </security>
    <security>
    <Symbol>IBM</Symbol>
    <Quantity>3000</Quantity>
    <Price>80.21</Price>
    <Value>1</Value>
    </security>
    <security>
    <Symbol>ADBE</Symbol>
    <Quantity>10000</Quantity>
    <Price>32.56</Price>
    <Value>1</Value>
    </security>
    <security>
    <Symbol>GOOG</Symbol>
    <Quantity>3000</Quantity>
    <Price>380.21</Price>
    <Value>1</Value>
    </security>
    </portfolio>

  • Strange Behaviour on DataGrid with ArrayCollection as DataProvider

    I have a Datagrid with an ArrayCollection as DataProvider, the arrayCollection is partially generated by a remoteObject call, the dataprovider seems to works at least until I try to edit the field...
    By the RemoteObject I only receive an ArrayCollection with the field `ip`, but the datagrid looks for the fields ip, check and save...
    If I add/edit this new field it works, but only under particular condition
    The DataGrid:
    <s:DataGrid id="datagrid" left="10" right="10" top="136"
           dataProvider="{listaIPCheck}" bottom="10" requestedRowCount="4">
              <s:columns>
                    <s:ArrayList>
                         <s:GridColumn dataField="ip" headerText="Asset"/>
                         <s:GridColumn dataField="check" headerText="Inventory"/>
                         <s:GridColumn dataField="save" headerText="Salvataggio"/>
                    </s:ArrayList>
               </s:columns>
    </s:DataGrid>
    The Script:
       [Bindable]private var listaIPCheck:ArrayCollection;
        private function ro_resultHandler(event:Event=null):void
          listaIPCheck = new ArrayCollection();
          listaIPCheck = ro.getListUpdate.lastResult;
          heap = 0;
          // Read Below {POINT #1}
          init3();
        private function init3():void
         // Read Below {POINT #2}
         if (heap<listaIPCheck.length)
            // omitted the initialization of the process p
            p.addEventListener(NativeProcessExitEvent.EXIT, onExit);
            try{
              p.start(startupInfo);
            }catch(e:Error){}
        private function onExit(e:NativeProcessExitEvent):void {
            // Read below {POINT #3}
    Here is my code, now as you can see there are 3 line where I wrote to read below...
    Let's assume to put this simple `for` instead of the commented line (once at a time)
        for (var k:Number=0;k<listaIPCheck.length;k++)
          listaIPCheck.getItemAt(k).check = "checkVal";
          listaIPCheck.getItemAt(k).save = "saveVal";
    This code always work in the 3 points, so at the end of the call the ArrayCollection is always filled with the new values, but the datagrid refresh the items only in POINT #1 and POINT #2
    Why not in Point #3???

    Thank you Amy, but adding the properties in the server side did not work...
    The workflow of the program is that:
    1) I get the ArrayCollection (listaIPCheck) contatining some information  (function ro_resultHandler)
    2) I start an external process and grab the output data (function init3)
    3) read and use the data from the process (function onExit)
    Now the problem I have is regarding the refresh of the datagrid, this datagrid has the ArrayCollection (listaIPCheck) as DataProvider.
    So:
    - If I put the for loop instead of the comments  ( // Read Below {POINT #1} ) or
    ( // Read Below {POINT #2} )  it works, the ArrayCollection is updated and the datagrid is refreshed
    - Whereas if I put the for loop instead of  ( // Read Below {POINT #3} ) , it won't work.. or at least, the ArrayCollection is correctly updated, but the datagrid is not refreshed at all and I have to use .refresh()

  • DataGrid with dynamic columns & renderers

    I'm developing using Flash Builder 4 & Flex SDK 4.1.
    I need to manage very dynamic DataGrid components and keep their definitions, which are all part of a complex item renderer of an Offers list.
    The objects structure is simplified as follows -
    Data: Model --> Offers ArrayCollection --> Offer VO --> DataGrid data ArrayCollection & DataGrid columns Array
    View: List --> Offer Item Renderer --> DataGrid
    1. Since the DataGrid's columns property accepts only an Array (not ArrayCollection), it seems like Data Binding for defining the columns is very problematic.
    I tried to bind it to the source property of an ArrayCollection that would keep my columns definitions, but it didn't really work (mainly header display bugs).
    What is the recommended way to keep the dynamic columns definition of a DataGrid?
    2. Each column can have a set of dynamic properties, so I created a "mutant" - Column VO that extends DataGridColumn and got a dynamic properties ArrayCollection on it.
    The columns got a custom header renderer that includes an icon when there are properties.
    The header renderers got 4 main states (NotSelectedWithProperties, SelectedWithProperties, NotSelectedWithoutProperties & SelectedWithoutProperties).
    However, the header renderer area seems a bit buggy when maintaning dynamic columns.
    Any thoughts on the subject?
    3. Anyway, I ended up recreating the DataGrid's columns Array very often (copying the columns definition on the offer's item renderer's dataChange event handler).
    Note that the dynamic properties can be edited when the column is selected and I copy their values from the view back to the model when entering the state NotSelectedWithProperties.
    This feels way too complicated and I really try to keep it simple, inspite of the required complexity.
    Does anyone have better ideas?
    4. In some cases the column's item renderer should also be modified into another DataGrid (grid-in-grid).
    I used the MXDataGridItemRenderer with a DataGrid and included an ArrayCollection for the "newValue" returned by the editor.
    (I use RendererIsEditor=true and on updateComplete populate that variable with the DataGrid's dataProvider contents)
    When needed, I loop though the data objects of the parent DataGrid and populate the related field with an ArrayCollection of key-value objects that are displayed on the internal DataGrid.
    After adding this feature I encounter very strange bugs -
    a. After editing the grid-in-grid values and changing the column's state (selecting & deselecting), I get the following exception:
    ArgumentError. Error #2025: The supplied DisplayObject must be a child of the caller.
    at flash.display::DisplayObjectContainer/setChildIndex()
    at mx.core::UIComponent/setChildIndex().......6993....
    All I could find about this is that it might be related to some context error or something, but I'm really stuck on this one.
    b. Sometimes another column might copy value from one row to another, running over the previous value.
    I'm not sure exactly what sequence of actions causes this behavior, but it's related to that itemRenderer for sure.
    c. Switching places with a column that uses the grid item renderer (headerShift) causes a stak overflow of StyleManager that tried to get style from the DataGridItemRenderer. This one I just found out, but couldn't reproduce a second time... strange!
    I'm pretty sure this caused another problem that I don't remember at the moment.
    The bottom line is that there got to be a better way to implement this feature within this already-complicated environment.
    Maybe I'm doing something very wrong here...
    Please advice and thanks for reading all this.

    Update on item 4a -
    This was a major issue (the main reason for opening this thread really) and I managed to resolve it!
    As part of my application, I override the default DataGrid behavior for column selection (headerRelease event).
    Instead of sorting, I change the column's header looks and define it as Selected (for showing its dynamic properties and enable its deletion).
    At first I did this by setting styles, but the look didn't refresh unless I created a new instance of the header renderer.
    Later I changed thi behavior to work with states, but I left the new header renderer instance creation commands and those lines created all the mess!
    Conclusion -
    If you define a custom header renderer for your datagrid column and then a custom item renderer, don't create a new instance of your header renderer!
    It would still be nice to get some response for the other issues I raised.
    Thanks and have a nice week.

  • 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)

  • Need for a Datagrid with variableRowHeight="true" and custom Item Renderer to display exact rows

    Hi again, developers:
    I'm in a search of a datagrid  with certain characteristics:
         - variableRowHeight = "true"
         - only one column
         - each row must have a custom item renderer with possibly different heights, and a fixed width
         - the datagrid must show always every item in the data provider with no vertical scroll bars, what means that the datagrid height must have always the exact height sum of all the item renderers it is displaying.
         - and no extra empty rows must appear in the last positions of the datagrid
    The last two requirements are something difficult to achieve... for some reason, empty rows appear at the last positions of the datagrid. I post what i've managed to get:
    <mx:Script>
         <![CDATA[
         private function resize():void
                    if (dg.dataProvider)
                        var h:Number = dg.measureHeightOfItems( -1, dg.dataProvider.length);
                        dg.height = h;
         ]]>
    </mx:Script>
    <mx:DataGrid id="dg" width="530" horizontalCenter="0" verticalScrollPolicy="off"
            dataProvider="{dp}"
            wordWrap="true" variableRowHeight="true" showHeaders="false" dataChange="resize()" height="{dg.measureHeightOfItems(-1,dg.dataProvider.length)}" click="Alert.show(dg.rowCount.toString());">
            <mx:columns>
                <mx:DataGridColumn headerText="ID" width="50">
                    <mx:itemRenderer>
                        <mx:Component>
                            <mx:TextArea height="{Math.random()*100}" wordWrap="true" backgroundColor="{Math.random() * 16777216}" paddingTop="0" paddingBottom="0"/>
                        </mx:Component>
                    </mx:itemRenderer>
                </mx:DataGridColumn>
            </mx:columns>
        </mx:DataGrid>

    Thanks Harui, but it doesn't help. If the border is set it will help, but the very big problem is the empty rows that appear at the end of the datagrid... I can't find a way of measuring correctly the height of the itemRenderers!
    I'll update this thread if I manage to do it.

  • Editable DataGrid With DateField

    I'm new to flex and struggling with the editable DataGrid. I
    have a DataGrid with an ItemRenderer that outputs a DateField. I
    can't figure out how to get the new value of the DateField after
    the edit.
    Here is my DataGrid (the endDate column):
    <mx:DataGrid id="allHistoryGrid"
    dataProvider="{allEntries}" height="313" width="782" y="-4"
    itemEditEnd="saveGridChange(event)" editable="true">
    <mx:columns>
    <mx:Array>
    <mx:DataGridColumn dataField="dietDescription"
    headerText="Diet"/>
    <mx:DataGridColumn dataField="allergyDescription"
    headerText="Allergy"/>
    <mx:DataGridColumn dataField="labDescription"
    headerText="Lab"/>
    <mx:DataGridColumn dataField="labResult" width="50"
    headerText="Result" itemRenderer="LabResultItemRenderer"/>
    <mx:DataGridColumn dataField="medicationDescription"
    headerText="Medication"/>
    <mx:DataGridColumn dataField="height" width="65"
    headerText="Height" itemRenderer="HeightItemRenderer"/>
    <mx:DataGridColumn dataField="weight" headerText="Weight"
    itemRenderer="WeightItemRenderer"/>
    <mx:DataGridColumn dataField="bmi" width="35"
    headerText="BMI" itemRenderer="BmiItemRenderer"/>
    <mx:DataGridColumn dataField="circumference" width="45"
    headerText="Circ." itemRenderer="CircumferenceItemRenderer"/>
    <mx:DataGridColumn headerText="Start Date" width="75"
    sortCompareFunction="startDateSortCompare">
    <mx:itemRenderer>
    <mx:Component>
    <mx:VBox clipContent="false">
    <mx:DateFormatter id="dateFormatter"
    formatString="MM/DD/YYYY"/>
    <mx:Text width="100"
    text="{dateFormatter.format(data.startDate)}"/>
    </mx:VBox>
    </mx:Component>
    </mx:itemRenderer>
    </mx:DataGridColumn>
    <mx:DataGridColumn dataField="endDate" width="45"
    headerText="End Date" itemRenderer="EndDateItemRenderer"
    rendererIsEditor="true"/>
    <mx:DataGridColumn id="deleteEntry" width="50"
    textAlign="center"
    headerText="Delete" sortable="false"
    itemRenderer="DeleteItemRenderer"/>
    </mx:Array>
    </mx:columns>
    </mx:DataGrid>
    Here is my itemRenderer:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:VBox xmlns:mx="
    http://www.adobe.com/2006/mxml"
    paddingLeft="16" horizontalAlign="center">
    <mx:DateFormatter id="dateFormatter"
    formatString="MM/DD/YYYY"/>
    <mx:DateField x="16" y="67" id="AllHistoryEndDate"
    text="{dateFormatter.format(data.endDate)}"/>
    </mx:VBox>
    How do I get the new value in the saveGridChange function?
    private function saveGridChange(event:DataGridEvent):void {

    That gives me this error:
    TypeError: Error #1034: Type Coercion failed: cannot convert
    EndDateItemRenderer@51a70a1 to mx.controls.TextInput.

  • DataGrid with Custom Component not showing sub-components

    I'm hoping someone can enlighten me on this issue.
    I have a datagrid with one column which has an item renderer. It doesn't matter if the "text" data comes from a dataProvider or is static.
    If I do the following, only the first label will show up.
    <mx:DataGridColumn headerText="Column Title">
         <mx:itemRenderer>
               <mx:Component>
                   <mx:VBox>
                        <mx:Label text="{data.data1}" />
                        <mx:Label text="{data.data2}" />
                   </mx:VBox>
              </mx:Component>
         </mx:itemRenderer>
    </mx:DataGridColumn>
    However, if I change the VBox to a HBox both labels will show up.
    <mx:DataGridColumn headerText="Column Title">
          <mx:itemRenderer>
                <mx:Component>
                    <mx:HBox>
                        <mx:Label text="{data.data1}" />
                         <mx:Label text="{data.data2}" />
                    </mx:HBox>
               </mx:Component>
          </mx:itemRenderer>
    </mx:DataGridColumn>
    I'm using:
    Flex Builder 3 Standalone
    Version: 3.0.214193
    OS: Vista
    Any ideas or comments would be appreciated.

    Thanks for the reply KomputerMan.com. I've tried changing the dimensions of the VBox and no other labels appeared. Usually, when there is not enough room within the datagrid cell scrollbars will appear - you can experiment with the example below to see what I mean.
    As for radiobuttons in a datagrid, here you go. The DataGrid and its dataProvider are constructed in the same way you normally would.
    <mx:DataGridColumn headerText="Approve/Deny/Pending" width="170">
        <mx:itemRenderer>
            <mx:Component>
                <mx:HBox height="27" paddingLeft="10">
                    <mx:Script>
                        <![CDATA[
                            private function isSelected(s:Object, val:String):Boolean {
                                if ( s.toString() == val) {
                                    return true;
                                } else {
                                    return false;
                        ]]>
                    </mx:Script>
                    <mx:RadioButton groupName="approveType"
                        id="approved"
                        label="A"
                        width="33"
                        click="data.status='1'"
                        selected="{isSelected(data.status, '1')}"/>
                    <mx:RadioButton groupName="approveType"
                        id="denied"
                        label="D"
                        width="33"
                        click="data.status='2'"
                        selected="{isSelected(data.status, '2')}/>
                    <mx:RadioButton groupName="approveType"
                        id="Pending"
                        label="P"
                        width="33"
                        click="data.status='3'"
                        selected="{isSelected(data.status, '3')}/>
                </mx:HBox>
            </mx:Component>
        </mx:itemRenderer>
    </mx:DataGridColumn>

  • Spark DataGrid with Dynamic Column Width

    Lets suppose I have a Spark Datagrid with no explicit typicalItem. When the Datagrid is initialized, the column widths are calcualted correctly based on the contents of the dataprovider. However if I add/remove an item from the dataprovider, or modify the one of the objects in the dataprovider, the column widths never update to reflect the change. Is the the correct behavior for a DataGrid? If so, is there any method I can call to force the DataGrid to recalculate and redraw the column widths?

    When Spark DataGrid doesn't have a typicalItem, it uses the first dataProvider item as the typicalItem.  If you change that, the DataGrid won't pick it up immediately. You can invalidate the current typicalItem using dataGrid.invalidateTypicalItem().

  • DataGrid with dynamic comboboxes

    I need to design a dataGrid with comboboxes in one column. These comboboxes should all have different dataProviders based on a value from column 1. What would a general approach be?
    Thanks

    The renderer's data property is the data for the entire row so you can get the column1 data and assign the combobox's dataprovider accordingly.
    Alex Harui
    Flex SDK Developer
    Adobe Systems Inc.
    Blog: http://blogs.adobe.com/aharui

  • Item renderer in datagrid with actionscript

    Hi
    I want to implement a datagrid similar to the one given int
    the starting flex examples but in actionscript. I am having a
    problem with the itemRenderer. I can't figure it out how I cam
    create a imagerender in a datagridcolumn.
    My code is:
    var dataG:DataGrid = new DataGrid();
    dataG.dataProvider = xmlList;
    var coluna:DataGridColumn = new DataGridColumn();
    coluna.dataField="nome";
    coluna.headerText="Title";
    var coluna2:DataGridColumn = new DataGridColumn();
    coluna2.dataField="thumbnail";
    coluna2.headerText="Title";
    var imagem:Image = new Image();
    imagem.height = 75;
    imagem.source = "../tb/"+instrumentos.thumbnail+".jpg";
    //HERE RELIES MY PROBLEM -HOW TO ASSOCIATE AN IMAGE TO THE
    ITEM RENDERER
    coluna2.itemRenderer = new ClassFactory(imagem);
    var lalala:Array = new Array();
    lalala.push(coluna);
    lalala.push(coluna2);
    dataG.columns = lalala;
    thanks in advance

    "jahh_drum" <[email protected]> wrote in
    message
    news:ghcs5u$p2d$[email protected]..
    > Hi
    >
    > I want to implement a datagrid similar to the one given
    int the starting
    > flex
    > examples but in actionscript. I am having a problem with
    the itemRenderer.
    > I
    > can't figure it out how I cam create a imagerender in a
    datagridcolumn.
    >
    > My code is:
    >
    > var dataG:DataGrid = new DataGrid();
    > dataG.dataProvider = xmlList;
    >
    > var coluna:DataGridColumn = new DataGridColumn();
    > coluna.dataField="nome";
    > coluna.headerText="Title";
    >
    > var coluna2:DataGridColumn = new DataGridColumn();
    > coluna2.dataField="thumbnail";
    > coluna2.headerText="Title";
    >
    >
    > var imagem:Image = new Image();
    > imagem.height = 75;
    > imagem.source = "../tb/"+instrumentos.thumbnail+".jpg";
    >
    > //HERE RELIES MY PROBLEM -HOW TO ASSOCIATE AN IMAGE TO
    THE ITEM
    > RENDERER
    > coluna2.itemRenderer = new ClassFactory(imagem);
    >
    > var lalala:Array = new Array();
    > lalala.push(coluna);
    > lalala.push(coluna2);
    >
    > dataG.columns = lalala;
    ClassFactory takes a class, not an instance.
    Try something like:
    foo:ClassFactory = new ClassFactory(Image)
    foo.properties= {height=75,
    source:"../tb/"+instrumentos.thumbnail+".jpg"};
    coluna2.itemRenderer = foo;
    Note that using a ClassFactory this way will give you the
    same image in
    every renderer to start out with. However, I believe that
    image
    itemRenderers by default will take their source from the data
    property when
    that gets set.
    HTH;
    Amy

  • A DataGrid with a Custom ItemRenderer

    Hi all,
    I have a DataGrid whose DataProvider is bound to a simple Array. I have a custom ItemRenderer that includes a button that can remove the item itself (I don't want two separate columns with a remove button in one of them). However, I don't understand the behaviour - clicking the button rearranges the data in the DataGrid and sometimes duplicate the entries! See the example attached. Any idea what's happening?
    Martin.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="onCreationComplete();" xmlns:local="*">
        <mx:Script>
            <![CDATA[
                [Bindable]
                public var _data : Array;
                protected function onCreationComplete() : void {
                    _data = new Array();
                    _data.push(1, 2, 3, 4, 5);
            ]]>
        </mx:Script>
        <mx:VBox>
            <mx:DataGrid dataProvider="{_data}">
                <mx:columns>
                    <mx:DataGridColumn>
                        <mx:itemRenderer>
                            <mx:Component>
                                <mx:HBox implements="mx.controls.listClasses.IDropInListItemRenderer" creationComplete="dataLabel.text = String(data);">
                                    <mx:Script>
                                        <![CDATA[
                                            import mx.collections.ArrayCollection;
                                            import mx.controls.DataGrid;
                                            import mx.controls.listClasses.BaseListData;
                                            protected var _listData : BaseListData;
                                            public function get listData() : BaseListData {
                                                return _listData;
                                            public function set listData(d : BaseListData) : void {
                                                _listData = d;
                                            protected function onClick(e : Event) : void {
                                                var dp : ArrayCollection = (owner as DataGrid).dataProvider as ArrayCollection;
                                                dp.removeItemAt(listData.rowIndex);
                                        ]]>
                                    </mx:Script>
                                    <mx:Label id="dataLabel" width="100%" />
                                    <mx:Button click="onClick(event);"/>
                                </mx:HBox>
                            </mx:Component>
                        </mx:itemRenderer>
                    </mx:DataGridColumn>
                </mx:columns>
            </mx:DataGrid>
        </mx:VBox>
    </mx:Application>

    creationComplete is rarely used in renderers.  See the itemrenderer posts on my blog
    Alex Harui
    Flex SDK Developer
    Adobe Systems Inc.
    Blog: http://blogs.adobe.com/aharui

  • Problem filling DataGrid with XML - Object or ArrayCollection?

    Hi,
    I am trying to fill a datagrid with an XML file, rendered
    from a PHP
    script.
    The problem is that - first time there is only one entry in
    the XML
    file, so when I receive the data using
    event.result.root.child, I get
    an Object. But second time, when there are two entries in the
    XML
    file, the return type becomes an ArrayCollection of "child"
    type
    objects.
    This causes a problem when setting dataprovider of a
    DataGrid....
    So is there a way I can know what is the return type from the
    XML
    file, i.e., whether it is an Object or an ArrayCollection, so
    that I
    can set the dataprovider accordingly?

    In E4x
    If you have an xml structure like so:
    <parent prop1='someValue' >
    <child prop1='someValue' />
    </parent>
    to reference the parent use event.result
    to get the child use: event.result.child; to get the child
    attr: event.result.child.@prop1;

  • Editable Datagrid with LabelFunction Problems

    Hi,
    I'm having problems with a datagrid with editable columns and labelFunctions.
    The problem is that when i leave the editable field by a way that wasnt with Escape Key, the datagrid apply again the labelFunction and destroy the number formattion adding a lot of numbers.
    When the field is filled with 0000,00 he just adds more zeros, like 0.000.000,0000 and keep going after do the same process.
    And when the field has a number different of zero, he apply the labelFunction then after he remove the labelFunction. After few times it just make the number vanish and the cell goes empty.
    I read the documentation about editing cell and tryed to implement a solution to prevent the cell be edited, without sucess.
    The source code goes attached for some advice on my problem.
    Thanks, Fredy.

    Hi,
    I solved a part of problem with some changes that i've made.
    Now there is no problem with values different of zero, when i got just number, its fine, but still have problems with zero values.
    The snippet code goes next, the bold part that was modified from the last sample.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
         layout="vertical"
         backgroundColor="white">
         <mx:Script>
              <![CDATA[
                   import mx.controls.Alert;
                   import mx.events.DataGridEventReason;
                   import mx.controls.TextInput;
                   import mx.controls.dataGridClasses.DataGridColumn;
                   import mx.formatters.NumberFormatter;
                   import mx.events.DataGridEvent;
                   import mx.collections.ArrayCollection;
                   [Bindable] private var collection:ArrayCollection = new ArrayCollection([
                        {code:1, description:"Item 1", value:4564654},
                        {code:2, description:"Item 2", value:00000000},
                        {code:3, description:"Item 3", value:00000000},
                        {code:4, description:"Item 4", value:00000000},
                        {code:5, description:"Item 5", value:00000000},
                        {code:6, description:"Item 6", value:00000000},
                        {code:7, description:"Item 7", value:00000000}
                   private var formatter:NumberFormatter;
                   private function formatterFunction(item:Object, column:DataGridColumn):String {
                      if (formatter == null){
                           formatter = new NumberFormatter();
                           formatter.decimalSeparatorTo = ",";
                           formatter.thousandsSeparatorTo = ".";
                           formatter.decimalSeparatorFrom  = ",";
                           formatter.thousandsSeparatorFrom = ".";
                           formatter.useThousandsSeparator = true;
                           formatter.precision = 4;
                      return formatter.format(item[column.dataField]);
                 private function editEndHandler(event:DataGridEvent):void {
                    var myEditor:TextInput = TextInput(event.currentTarget.itemEditorInstance);
                    var newVal:Number = isNaN(Number(myEditor.text)) ? myEditor.text as Number : 0.0000;
                    var oldVal:Number = Number(event.currentTarget.editedItemRenderer.data[event.dataField]);
                     // it solves the partial part of the problem, but still have some errors
                     if (event.reason == DataGridEventReason.CANCELLED || event.reason == DataGridEventReason.OTHER) {
                        return;
                    if (oldVal == newVal ) {
                             // i've tryed this, but the itemEditor still open
                             event.preventDefault();
                             // if I just put 'return', still have the same problem
                             // return;
              ]]>
         </mx:Script>
         <mx:Label text="Bug datagrid editavel com labelFunction"
              fontSize="16"
              fontWeight="bold" />
         <mx:DataGrid dataProvider="{collection}"
              editable="true"
              itemEditEnd="editEndHandler(event)">
              <mx:columns>
                   <mx:DataGridColumn headerText="Código"
                        dataField="code"
                        editable="false"/>
                   <mx:DataGridColumn headerText="Descrição"
                        dataField="description"
                        editable="false"/>
                   <mx:DataGridColumn headerText="Valor"
                        width="300"
                        dataField="value"
                        labelFunction="formatterFunction"
                        editable="true"/>
              </mx:columns>
         </mx:DataGrid>
    </mx:Application>
    @Alex
    Thanks for the answer.
    I want to edit this column, but if there is no 'change' i dont want to apply again the label function and close the itemEditor.
    I've tryed to call event.preventDefault() but i dont know what to do next.
    Do you have some advice how to solve my problem?
    This is just happening when i got zero values on my datagrid =/
    Thanks all for the answers.

Maybe you are looking for

  • Company Code One Vs multiple

    Hi Experts, I would like know that if we merge multiple company code to one company code. then what would be legal impact and vice versa. Regards,

  • CCMS - Alert Monitoring

    Dear All, I have just installed IDES 4.7 Release SR 2.0 Now I want to configure Alert Monitoring using RZ20. Can you please explain step by step as I am new person in the CCMS area. Thanks in advance LK

  • Speed Up Photoshop (and Everything) With SSD

    'Tis the season to spend money. FYI, today on Amazon.com you can get a ridiculously fast 256GB OCZ Vertex 4 SSD drive for only $159.99, which is an unprecedented low price for a drive of this capacity. http://www.amazon.com/OCZ-Technology-2-5-Inch-In

  • Http server start/stop process

    Hi I always see below start/stop messages in the D:\app\Oracle\opmn\logs\HTTP_Server~1 We are not stopping/starting anything. Does it mean that the http server stop/start itself ? Will this affect users ? 12/06/07 23:18:12 Start process 12/06/26 10:0

  • Lost key for 60 days trial version of Office 2007.

    Hi, I accidently deleted shortcut to 60 days tial which was included when \i purchased my laptop. Are there any ways ow to find this lost key? "To get a valid product key double click on the icon "Microsoft Office - 60 Day Trail" on the desktop an fo