DataGrid and DataProvider

Hello,
Could you explain me we how access different Node Level of an
XML dataProvider, from a DataGrid ??
Thanks very much

I posted a similar question on another site, have not heard
anything back yet.
http://www.actionscript.org/forums/showthread.php3?t=146034
when having e4x or XMLCollection as dataProvider, it seems
impossible to access anything but the immediate children or
immediate attributes from the root. I found a hack to get around
it, but it makes little sense to me. Here's a link:
http://www.adobe.com/devnet/flex/articles/e4x_04.html.
The suggestion described in the link works, but the resultant rows
are no longer sortable by the affected columns.
I played around with Laszlo and i know that Grid works in
it's simplest form in Laszlo just fine. Can someone help me
understand why there is a need to have a separate function of
parsing e4x to display in the DataGrid.
Thanks

Similar Messages

  • How to delete a selected row from datagrid and how to create a datagrid popup

    hi friends,
                  I am new to flex.i am doing a flex4 application,i need help for this.
                i am having a data grid with columns.i have two questions.
               Ques 1: when  i selected a partiuclar row from a datagrid and click delete button  means that record will delete from the datagrid and DTO from the cloud  tables also.
                Ques 2: when i save  the data grid values using save button means that data will store in  respective cloud DTO which is related to the datagrid,
                     My requirement is i am using a search button when i click the search  button it will show a datagrid that datagrid will contain the previous  datagrid datas which is saved in the cloud.
    REQUIREMENT example: first screen:           i am using with data grid 3 columns (Student Roll number ,Student Name,Student pecentage)---->save--->data will store in cloud DTO.
    Second screen:                search button ----> it need show  datagrid popup.it will have data which we saved in the first screen with same columns(Student Roll number ,Student Name,Student pecentage).
    This is my requirement.
    Any suggession welcome.
    Thanks in advance.
    B.Venkatesan

    Lets break the problem statement in multiple steps
    1. We need a way to know the selection on all rows.
    2. We need the association of the checkBox with the data
    The  solution is to use a arrayCollection/array that holds all the instances  created for checkbox.This collection should be a property of component  containing the datagrid. We need to use a custom component  implementation or inline ItemRenderer. The way you have used is called  dropinItemRenderer. Preferaly use custom component implementation and  add the instance to the arrayCollection at CreationComplete. Make sure  you use addItemAt so that you add the instance in the same row as the  data. To get rowIndex the custom Checkbox should implement  IDropInListItemRenderer. You could iterate this collection to check all  the instances that are checked.
    Note: This is the approach considering your dataprovider doesnt have a selection field.
    Nishant

  • How to delete a Selected row from datagrid and how to create a datagrid popup with saved values

    hi friends,
                  I am new to flex.i am doing a flex4 application,i need help for this.
                i am having a data grid with columns.i have two questions.
               Ques 1: when i selected a partiuclar row from a datagrid and click delete button means that record will delete from the datagrid and DTO from the cloud tables also.
                Ques 2: when i save the data grid values using save button means that data will store in respective cloud DTO which is related to the datagrid,
                    My requirement is i am using a search button when i click the search button it will show a datagrid that datagrid will contain the previous datagrid datas which is saved in the cloud.
    REQUIREMENT example: first screen: i am using with data grid 3 columns (Student Roll number ,Student Name,Student pecentage)---->save--->data will store in cloud DTO.
    Second screen: search button ----> it need show  datagrid popup.it will have data which we saved in the first screen with same columns(Student Roll number ,Student Name,Student pecentage).
    This is my requirement.
    Any suggession welcome.
    Thanks in advance.
    B.Venkatesan

    Lets break the problem statement in multiple steps
    1. We need a way to know the selection on all rows.
    2. We need the association of the checkBox with the data
    The  solution is to use a arrayCollection/array that holds all the instances  created for checkbox.This collection should be a property of component  containing the datagrid. We need to use a custom component  implementation or inline ItemRenderer. The way you have used is called  dropinItemRenderer. Preferaly use custom component implementation and  add the instance to the arrayCollection at CreationComplete. Make sure  you use addItemAt so that you add the instance in the same row as the  data. To get rowIndex the custom Checkbox should implement  IDropInListItemRenderer. You could iterate this collection to check all  the instances that are checked.
    Note: This is the approach considering your dataprovider doesnt have a selection field.
    Nishant

  • How2 load xml into datagrid, and create realtime search of datagrid data

    I wanted to be able to load xml data into a datagrid and then create a searchbox that would search in real time (as person typed) from any part of the datagrid.  Does anyone know of any as2.0 component that can do that easily?  If not, i would like to try to tackle this the old fashioned and use this to teach myself as2.0 advanced coding.  can someone point to a step by step or explain how i might get this accomplished?  from loading the xml to putting the node info into the datagrid, to being able to search it in real time.  This is part of a project that i was given that has some serious consequences if i botch it.  Please help!  Thanks so much!

    import fl.controls.DataGrid;
    import fl.controls.ScrollPolicy;
    import fl.data.DataProvider;
    import flash.net.URLLoader;
    import flash.events.Event;
    var dp:DataProvider = new DataProvider();
    var dg:DataGrid = new DataGrid();
    dg.columns=["User","Xp","Rank"];
    addChild(dg);
    var urlloader:URLLoader = new URLLoader();
    urlloader.addEventListener(Event.COMPLETE,loadcompleteF);
    urlloader.load(new URLRequest("whatever.xml"));
    function loadcompleteF(e:Event):void {
        var xml:XML=XML(e.target.data);
        for (var i:int = 0; i < xml..Name.length(); i++) {
            dp.addItem({User:xml..Name[i].User.text(), Xp:xml..Name[i].Xp.text(), Rank:xml..Name[i].Rank.text()});
        dg.dataProvider=dp;

  • DataGrid and labelFunction

    Hi all!
    I have a DataGrid, and I have two columns where i want to manipulate the data shown. I tried using a labelfunction, but it turns out the labelfunction is called each time I focus out, and not only when the DataGrid is initialized.
    I've seen theres an initialize for DataGrid, but how can i use this to manipulate the data from my two columns?
    Sincerly

    How do you wrap an object?  It depends on how you are getting your data.  If
    you are using RemoteObject or can control the data type being sent over the
    wire, I would simply add a new getter to the data class.
    The most rudimentary way is something like this:  Say you had a ShoppingCart
    record:
    class ShoppingCartRecord
        public var catalogID:int;
    A wrapper class might look like:
    class DisplayableShoppingCartRecord
        public function DisplayableShoppingCartRecord(orig:ShoppingCartRecord)
            original = orig;
        public var original:ShippingCartRecord;
        public function get catalogID():int
            return original.catalogID;
        private var _displayName:String;
        public function get displayName():String
            if (!_displayName)
                _displayName = yourOldLabelFunction(orig);
            return _displayName;
    Then at some point, you loop through the original data set and instantiate
    the wrapped versions and pass that dataprovider to the datagrid.

  • Synchronization between datagrid and chart Item

    Hi
    In my application, I have a datagrid and corresponding bar
    chart. there is a toggle button through which I can switch between
    chart and data grid.
    Now I want to synchronize both.
    for example If I select any 3 rows in data grid then it
    should selects 3 bars on the chart also.
    can any body help me in that?
    Thanks
    smonika15

    Hi,
    U need to have a combo box renderer something like:
    In the object that u are populating the data provider of the
    data grid, add 2 fields:
    listOfFields & selectedField.
    <mx:HBox horizontalScrollPolicy="off"
    verticalScrollPolicy="off"
    xmlns:mx="
    http://www.adobe.com/2006/mxml">
    <mx:Script>
    <![CDATA[
    public var itemSelected: Object;
    ]]>
    </mx:Script>
    <mx:ComboBox id="combo"
    dataProvider="{data.listOfFields}"
    selectedItem="{data.selectedField}"
    change="itemSelected=combo.selectedItem;"
    updateComplete="itemSelected=combo.selectedItem;">
    </mx:ComboBox>
    </mx:HBox>
    Now, loop through the list of objects that u get from
    back-end and keep setting the 2 new properties (listOfFields &
    selectedField). For setting the value of selectedField, u need to
    loop through listOfFields to match the fieldId.
    Hope that helps,
    Cheree

  • GridView vs DataGrid and gateway

    Used to use DataGrids and in a template field Hyperlink, the portal converts the link to a fully gatewayed link... GridView Hyperlinkfield does not get "gateway converted"? Thoughts? Guess I could use a TemplateField, but was hoping to use a more default solution.
    EDIT: it appears that a template column with a hyperlink in a GridView does not get "gateway converted" either, hmmmm. Back to tesing and tinkering
    EDIT: I am a moron....have to set the gateway prefix in teh Web Service.....jsut shoot me now! TGIF!
    Edited by: mbowles on Nov 7, 2008 7:56 AM
    Edited by: mbowles on Nov 7, 2008 8:00 AM

    Doh..built my web app in VS2008 w/o using the app accel / AquaLogicWCLoader. It started out as a LINQ o/r mapping experiment - but am trying to take a step further and get into the portal. I'll tweak the web app (referenes to idk and wcloader, web forms into partial classes inheriting from BEA.ALI.Web.UI.ALIPortletPage) and see if that fixes. I'll keep the group posted.
    Bah-zing! It worked. As usual, thanks again, Joel!
    Edited by: tjannotta on Feb 17, 2009 9:37 AM

  • Using same returned data to create datagrid and pie graph

    I am trying to find a good example or information on creating
    charts, initially pie graphs. I will be getting the data from a
    MySQL DB via a HTTPService call to a PHP script. I would like to
    use the same HTTPService call to make a datagrid and build a pie
    graph. My datagrid is working fine.
    All of the examples I have found show the app with an
    internal data source that's hard coded into an array (
    http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDo cs_Parts&file=00001234.html).
    I did search this forum, but it seems most people are just looking
    for dynamic pie graphs and there isn't enough in the entries for me
    to go off of.
    The data returned to the MXML app looks like this:
    <auditdata>
    <riskdata>
    <core>core number here</core>
    <subcore>subcore number here</subcore>
    <mdata>mdata here</mdata>
    <risk1>number here</risk1>
    <risk2>number here</risk2>
    <risk3>number here</risk3>
    </riskdata>
    <riskdata>
    <core>core number here</core>
    <subcore>subcore number here</subcore>
    <mdata>mdata here</mdata>
    <risk1>number here</risk1>
    <risk2>number here</risk2>
    <risk3>number here</risk3>
    </riskdata>
    </auditdata>
    When the data is returned, everything under <riskdata>
    is put into a datagrid. What I'm looking to do in the pie graph is
    this.
    Create a 2 different pie graphs for each riskdata (there will
    only be 2). The first pie graph will be of the three "risks" (where
    their total number equals 100% of the graph). The second pie graph
    would be "core - subcore" and risk1 (where the two values total
    equals 100%of the graph). I hope that makes sense.
    Any guidance would be truly appreciated.
    Thanks,
    Chris

    Does anyone have any ideas on this?
    Thanks,
    Chris

  • Datagrid and Inline Item renderer problem

    I have a datgrid with two inline item renderers. The dataprovider for my DG is a nested object (objects within objects within objects i.e 3-layered).
    Main Object - 1st Level
                              |
                  2nd Level Object 1
                                    |
                                3rd level object '1' => ('name'=>somename,'id'=>someid)
                                3rd level object '2'
                                3rd level object 'n'
                 2nd Level Object 2
                                    |
                                3rd level object '1' => ('name'=>somename,'id'=>someid)
                                3rd level object '2'
                                3rd level object 'n'
    I use 2 item renderers (one for each datagrid column) which loops thro the 2nd level object1 and 2 respectively (the 2nd level object is a dynamic array of objects, in that the number of objects within keep changing).
    Within the item renderer I loop thro the 2nd level object using a foreach and then display the data. The data is a linkbutton, which when clicked , calls a remote object function to delete the data from the database
    now on the result event of the remote object function call, i call the function to repopulate the DG, so that the updated data is displayed.
    When i click on the linkbutton in the first row, the backend works perfectly fine (the data gets deleted from the database and the refreshed data is sent back), but for some reason, the deleted data suddenly appears in the 2nd row.
    When i delete it from the second row, it appears on the 3rd row (nothing happens in the backend since the data is already deleted).. and so on, till it appears on the last row and then the DG looks exactly the way it shld have looked after the first delete.
    This is just the beginning. The second item renderer also displays a linkbutton, which when clicked, displays that data in the previous column (the one where this data can be deleted). When i click on 1st row, the data gets added in the previous column of the second row .. and so on..
    Basically, my DG is acting really weird. I overrided the set data function in the item renderer to refrsh the data and called its invalidateDisplayList. I also call the Datagrid's invalidateDisplayList function after each refresh.  The behavior remains the same.
    Please help me on this ...

    Hi, Post a test code.... It will be a lot easier to help you Mich

  • Datagrid and multiple ItemRenderer

    What I would like to do and haven't been successful is add a column to a Datagrid at runtime.  Each cell in that column is going to be different based upon user data. The first column is populated based upon a user query then another query (i.e. RESTful query) is made to mashup some data.
    I wanted a button (mashup data) to appear in the column enabled if data was available and disabled if data was not available.
    I was doing something like this:
    My MXML file has this:
            <mx:DataGrid id="dg" dataProvider="{ModelLocator.getInstance().list}" itemClick="itemClickHandler(event)" left="10" right="0" bottom="0" top="50" editable="true" >
                <mx:columns>
                    <mx:DataGridColumn headerText="Name" dataField="name" editable="true" />
                     <mx:DataGridColumn headerText="Data" dataField="someData" itemRenderer="ActionButtonItemRenderer" />
                </mx:columns>
            </mx:DataGrid>
    ActionButtonItemRenderer.as file:
        public class ActionButtonItemRenderer extends Button
            public function ActionButtonItemRenderer()
                super();
                label = "Show Data";
            override public function set data(value:Object):void {
                if (null == value.myData) {
                    label = "";
                    this.enabled = false;
            // Handle the search button event.
            override protected function clickHandler(event:MouseEvent):void
                // Code omitted here...
    It works but when I use my mouse wheel to scroll through the records the buttons get all hosed up and the enabled buttons become disabled.  It's weird.
    Thanks!

    You create an ArrayCollection or XMLListCollection and populate it initially with perhaps data that would represent "no data".
    Then if your queries return real data, the dataProvider object now "has data".
    The itemRenderer does the appropriate thing if there is not is no data.
    You don't generate the button in the dataProvider, you just get the label and visible property value etc. from the dataProvider.
    If this post answers your question or helps, please mark it as such.
    Greg Lafrance - Flex 2 and 3 ACE certified
    www.ChikaraDev.com
    Flex / AIR Development, Training, and Support Services

  • DataGrid Combobox dataprovider erasing items

    I have a DataGrid that is linked to an array of custom data objects which I call a seriesList.  You are supposed to be able to choose the name of each series via a combobox in the datagrid.  It works fine except when the user selects the combobox and then clicks somewhere else in the interface, which closes the combobox and erases whichever item is previously selected!
    <!--  Definition in application  -->
    <!--  axis.seriesList is and ArrayCollection of actionscript objects called SeriesObjects which have a var name:String variable -->
    <mx:DataGrid id="seriesTable" color="black" fontSize="9" rowHeight="30" editable="true" resizeEffect="slow" rollOverColor="#CCCCCC"
        selectionColor="#999999" dataProvider="{axis.seriesList}" width="100%"
        rowCount="{axis.seriesList.length > 2 ? axis.seriesList.length : 2}" >
            <mx:columns>  
                 <mx:DataGridColumn dataField="name" headerText="Name" width="280" headerStyleName="centered" id="nameColumn"
                         rendererIsEditor="true"  editorDataField="result" itemRenderer="renderer.SeriesBoxRenderer"/>
            </mx:columns>
    </mx:DataGrid>
    <!--  SeriesBoxRenderer -->
    <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" horizontalAlign="center">
       <mx:Script>
            <![CDATA[
                import mx.collections.ArrayCollection;
                // Define a property for returning the new value to the cell.
                public var result:String="";
                [Bindable]
                private var dpValue:ArrayCollection;
                private function init():void {
                    // list of possible names to choose from for this series
                    dpValue = mx.core.Application.application.seriesArray;
                // Override the set method for the data property.
                override public function set data(value:Object):void {
                    if (dpValue == null) init();
                    super.data = value;
                    if (value != null)     {
                        var currentValue:String = value.name;
                        var len:int = dpValue.length;
                        for (var i:int = 0; i < len; i++) {
                            if (dpValue[i].name == currentValue) {
                                editor.selectedIndex = i;
                                return;
                    editor.selectedIndex = 0;            }
                public function onChange():void {
                    var index:int = editor.selectedIndex;
                    result = dpValue[index].name;
                    data.name = dpValue[index].name;
            ]]>
        </mx:Script>
         <mx:ComboBox id="editor" textAlign="left" labelField="name" dataProvider="{dpValue}"  change="onChange()"/>
    </mx:VBox>

    I'm thinking the problem may be the dataprovider for the combobox.  This array is also shared with another List component in another tab on the interface.  The reason I am thinking this is because I have another item renderer which uses a combobox and does not erase itself when you click nothing.  Here is the code for that item, and the only difference I can see between this code and the code that doesn't work is the fact that the dataprovider is shared with another part of the code.  Still not sure how to fix this, however.
              [Bindable]
                private var dpValue:ArrayCollection;
                private function init():void {
                    dpValue = mx.core.Application.application.aquisitionOptions.lastResult.system.data;
                    for ( var i:int=0; i<dpValue.length; i++ )  {  //loop over the items in the dataProvider
                       if (dpValue[i].id == data.aquisitionID)  {  //compare desired value to current item.data value
                            editor.selectedIndex = i;  //set the seletedIndex of the combo box
                            data.aquisitionDescr = dpValue[i].name;
                            break;
              // Override the set method for the data property.
                override public function set data(value:Object):void {
                    super.data = value;
                    if (dpValue == null) init();
                    if (value != null)     {        
                        var currentValue:String = value.aquisitionDescr;
                        trace ("\n current:  ", currentValue);
                        var len:int = dpValue.length;
                        for (var i:int = 0; i < len; i++) {
                            if (dpValue[i].name == currentValue) {
                                editor.selectedIndex = i;
                                return;
                    editor.selectedIndex = 0;
                public function onChange():void {
                    var index:int = editor.selectedIndex;
                    result = dpValue[index].name;
                    data.aquisitionDescr = dpValue[index].name;
                    data.aquisitionID = editor.selectedItem.id as String;
            ]]>
        </mx:Script>
         <mx:ComboBox id="editor" labelField="name" dataProvider="{dpValue}" change="onChange()"/>
    <!-- definition in the datagrid -->
    <mx:DataGridColumn dataField="aquisitionDescr" headerText="Data Aquisition" width="160" headerStyleName="centered" id="acquisitionColumn"
                         rendererIsEditor="true"  editorDataField="result" itemRenderer="renderer.AquisitionBoxRenderer"/>

  • 2 way databinding between DataGrid and DropDownList

    I am not getting anywhere with what I thought is the most simplest basic thing in the world.
    I have a ArrayCollection "employees" which is used to fill a DataGrid. The department is listed as an Integer value. I would like to display however the name of the department, which is in a second ArrayCollection "departmentsArray". So the itemRenderer (which is not yet implemented in this code) needs to match the "idn" value with the "departmentid" value and then display the name of the department. However, when the user clicks on the DropDownLists and selects a new department, the departmentid value in the employee array needs to get updated too.
    I am assuming that this can be done with 2 way databinding, but I am not getting this to work and would greatly appreciate if someone could show me how the code would have to look for this.
    Michael
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                      xmlns:s="library://ns.adobe.com/flex/spark"
                      xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
         <fx:Declarations>
              <!-- Platzieren Sie nichtvisuelle Elemente (z. B. Dienste, Wertobjekte) hier -->
         </fx:Declarations>
         <fx:Script>
              <![CDATA[               
                   import mx.collections.ArrayCollection;
                   [Bindable]
                   private var employees:ArrayCollection = new ArrayCollection([
                        {idn:1, firstname:'Lisa', lastname:'Tran', departmentid:1},
                        {idn:2, firstname:'Michael', lastname:'Orchard', departmentid:2},
                        {idn:3, firstname:'Wolfgang', lastname:'Prettyer', departmentid:2},
                        {idn:4, firstname:'Julia', lastname:'Stancau', departmentid:3},
                   [Bindable]
                   private var departmentsArray:ArrayCollection = new ArrayCollection([
                        {idn:1, department:'Video'},
                        {idn:2, department:'Web'},
                        {idn:3, department:'Print'},
              ]]>
         </fx:Script>
         <s:DataGrid x="57" y="90" width="410" requestedRowCount="4" dataProvider="{employees}">
              <s:columns>
                   <s:ArrayList>
                        <s:GridColumn dataField="idn" headerText="ID"></s:GridColumn>
                        <s:GridColumn dataField="firstname" headerText="Vorname"></s:GridColumn>
                        <s:GridColumn dataField="lastname" headerText="Nachname"></s:GridColumn>
                        <s:GridColumn dataField="departmentid" headerText="Department"></s:GridColumn>
                   </s:ArrayList>
              </s:columns>
         </s:DataGrid>
    </s:Application>

    Thanks for the info.
    I've only seen info about Snow Leopard syncing (and it doesn't really specify 2 way) to Exchange (which is not LDAP)
    Addressbookserver (www.addressbookserver.com) is also not LDAP.
    I really need this to work (2 way sync) with an LDAP server.
    Thanks.

  • DataGrid and XML with only 1 entry

    Hi All,
    I have a datagrid set up that is displaying an xml file.
    Seems to work fine until there is only 1 entry in my xml file, then
    I get no content displayed in the datagrid.
    Here is my code that I am using for my app,
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute" initialize="xmlDat.send()">
    <mx:Script>
    <![CDATA[
    import mx.controls.dataGridClasses.DataGridColumn;
    import mx.collections.ArrayCollection;
    import mx.rpc.events.ResultEvent;
    [Bindable]
    private var myData:ArrayCollection;
    private function resultHandler(event:ResultEvent):void{
    myData = event.result.projects.project;
    ]]>
    </mx:Script>
    <mx:HTTPService id="xmlDat" url="data/whiteboard.xml"
    result="resultHandler(event)"/>
    <mx:Panel layout="absolute" title="Project Whiteboard"
    height="600" width="1000" verticalCenter="-1"
    horizontalCenter="-1">
    <mx:DataGrid dataProvider="{myData}" width="980"
    height="560" y="0" x="0" verticalScrollPolicy="on"
    variableRowHeight="true" editable="false">
    <mx:columns>
    <mx:DataGridColumn headerText="Due Date"
    dataField="dueDate" width="85"/>
    <mx:DataGridColumn headerText="DVD ID" dataField="dvdId"
    width="65"/>
    <mx:DataGridColumn headerText="School Name"
    dataField="schoolName" width="275"/>
    <mx:DataGridColumn headerText="City" dataField="city"
    width="100"/>
    <mx:DataGridColumn headerText="St" dataField="state"
    width="35"/>
    <mx:DataGridColumn headerText="Qty" dataField="quantity"
    width="45"/>
    <mx:DataGridColumn headerText="Image Prep"
    dataField="imagePrep" itemRenderer="render.imgRender"/>
    <mx:DataGridColumn headerText="Video Prep"
    dataField="videpPrep" itemRenderer="render.vidRender"/>
    <mx:DataGridColumn headerText="Sequencing"
    dataField="sequencing" itemRenderer="render.seqRender"/>
    <mx:DataGridColumn headerText="FTP" dataField="ftp"
    itemRenderer="render.ftpRender"/>
    </mx:columns>
    </mx:DataGrid>
    </mx:Panel>
    </mx:Application>

    quote:
    Originally posted by:
    peterent
    When there is only 1 entry in the result you don't have an
    Array any more, you have a scalar. That's because the Player
    doesn't know you intend or want to always have an Array.
    Look up ArrayUtils and the toArray function. That should
    help.
    This sounds like just what I need. The only problem I am
    having now is how to implement it into my code. When I add it to
    the code it works for when I have one entry but if it is more than
    that then no data shows.
    Anyone have some ideas on this? Here is my updated code that
    works for one entry in the xml but not more than that.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute" creationComplete="initApp()">
    <mx:Script>
    <![CDATA[
    import mx.controls.dataGridClasses.DataGridColumn;
    import mx.collections.ArrayCollection;
    import mx.rpc.events.ResultEvent;
    import mx.utils.ArrayUtil;
    [Bindable]private var myData:ArrayCollection;
    private var uintPollInterval:uint = 10000;
    private var timer:Timer = new Timer(uintPollInterval);
    private function initApp():void
    xmlDat.send();
    timer.addEventListener(TimerEvent.TIMER, onTimer);
    timer.start();
    private function onTimer(event:TimerEvent):void
    xmlDat.send();
    timer.start();
    ]]>
    </mx:Script>
    <mx:HTTPService id="xmlDat" url="data/whiteboard.xml"
    result="resultHandler(event)"/>
    <mx:Panel layout="vertical" title="Project Whiteboard"
    height="100%" width="1000" verticalCenter="-1"
    horizontalCenter="-1">
    <mx:DataGrid
    dataProvider="{ArrayUtil.toArray(xmlDat.lastResult.projects.project)}"
    width="980" height="100%" y="0" x="0" verticalScrollPolicy="on"
    variableRowHeight="true" editable="false">
    <mx:columns>
    <mx:DataGridColumn headerText="Due Date"
    dataField="dueDate" width="85"/>
    <mx:DataGridColumn headerText="DVD ID" dataField="dvdId"
    width="65"/>
    <mx:DataGridColumn headerText="School Name"
    dataField="schoolName" width="275"/>
    <mx:DataGridColumn headerText="City" dataField="city"
    width="100"/>
    <mx:DataGridColumn headerText="St" dataField="state"
    width="35"/>
    <mx:DataGridColumn headerText="Qty" dataField="quantity"
    width="45"/>
    <mx:DataGridColumn headerText="Image Prep"
    dataField="imagePrep" itemRenderer="render.imgRender"/>
    <mx:DataGridColumn headerText="Video Prep"
    dataField="videpPrep" itemRenderer="render.vidRender"/>
    <mx:DataGridColumn headerText="Sequencing"
    dataField="sequencing" itemRenderer="render.seqRender"/>
    <mx:DataGridColumn headerText="FTP" dataField="ftp"
    itemRenderer="render.ftpRender"/>
    </mx:columns>
    </mx:DataGrid>
    <mx:ControlBar horizontalAlign="right">
    <mx:Button label="Update" click="xmlDat.send()"/>
    </mx:ControlBar>
    </mx:Panel>
    </mx:Application>

  • 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

  • Datagrid and checkbox renderer

    I'm looking to have a datagrid have a dataprovider from a coldfusion remote object in which i want to save a boolean value for checkboxes. i want the user to be able to select and deselect checked items and submit to a back end DB where their changes are saved.
    Then on load I want the checkbox value to be selected or deselected based on their previously saved prefs. Checkbox item renderers are a re-occuring problem for me. There seems to be so many ways to implement them and so far using online examples they don't show how to save results to a DB and reload them based on a DB. please help
    code i'm currently trying to use (where ITEM_TYPE is a DB value of true or false) and the getCheckList.lastResult is made up of 7 rows with ITEM_TYPE and DESCRIPTION (the checkbox description for the user):
    <mx:DataGrid id="myDG" dataProvider="
    {parentApplication.ATService.getCheckList.lastResult}" variableRowHeight="
    true" width="
    500" height="250" editable="
    true">
    <mx:columns>
    <mx:DataGridColumn textAlign="center" width="25" dataField="ITEM_TYPE" itemRenderer="
    mx.controls.CheckBox" rendererIsEditor="
    true"editorDataField="
    selected"/>
    <mx:DataGridColumn dataField="DESCRIPTION" />
    </mx:columns >
    </mx:DataGrid>

    I tried that Blog. It doesn't show how to preload from a database the checked or unchecked values. I did figure it out on my own though after some hard work. Using the <mx:Component> tag is nice... but i found it can't reference anything in the component its in b/c anything under <mx:Componenet> is not of the same class. trick here is to add the parentDocument. prefix and you call anything you want. also found that a DB string value (or varchar) of "true" or "false" is not recognized as boolean by flex. So to check or uncheck based on a DB result set from a CF componenet you need to actually check the value. I've attached my sample code for anyone else having trouble with this:
    <mx:DataGrid id="chkListDG" dataProvider="{parentApplication.ATService.getCheckList.lastResult}"width="
    100%" height="100%">
    <mx:columns>
    <mx:DataGridColumn textAlign="center" headerText="" dataField="CHKLIST_ID" width="30">
    <mx:itemRenderer>
    <mx:Component>
    <mx:CheckBox selected="{data.CHK_STATUS == 'true'}" click="dbChange()">
    <mx:Script>
    <![CDATA[
    import mx.controls.Alert; 
    private function dbChange():void{ 
    if (parentDocument.chkListDG.selectedItem.CHK_STATUS == 'false'){parentDocument.chkListDG.selectedItem.CHK_STATUS =
    'true'}
    else{parentDocument.chkListDG.selectedItem.CHK_STATUS =
    'false'};
    parentApplication.ATService.chkListSave(parentDocument.chkListDG.selectedItem.CHKLIST_ID,p arentDocument.chkListDG.selectedItem.CHK_STATUS);
    ]]>
    </mx:Script>
     </mx:CheckBox>  
    </mx:Component>  
    </mx:itemRenderer>
     </mx:DataGridColumn>
     <mx:DataGridColumn headerText="Description" dataField="DESCRIPTION"/>
     <mx:DataGridColumn headerText="Value" dataField="CHK_STATUS"/>
     </mx:columns>  
    </mx:DataGrid>

Maybe you are looking for