4 Replies Latest reply on Dec 29, 2009 8:51 PM by artscan65

    Datagrid component, dataprovider dependent

    artscan65

      Hello, thanks in advance and sorry for my bad english,

       

      I want to make a new component based on the DataGrid component. The plan is like this:

       

      - Bind DG component to a AC dataprovider.

      - On component creationcomplete, check if the dataprovider has any records (if it was populated before so wont have to re-load)

      - If no then call a dataservice and return an AC from AMFPHP (returns array, converts it to AC)

      - Populate the DG with the result

       

      I have accomplished all the above BUT !!

      If i have a blank DG (no columns) when the data returns fills up the DG fine

      If i have pre-defined DataGridColumns then altho the DG gets filled with the objects and each object traces the correct object attribute? DG shows blank cells !! All the cells, and all blank... Tested tracing the DG object onClick and appear ok...

       

      I know is kinda weird request amd too complicated...

       

      Thanks

        • 1. Re: Datagrid component, dataprovider dependent
          chris.huston.t10

          Did you set the dataField property for your pre-defined DataGridColumns to match the fields in your dataset from AMFPHP? If you are seeing blank cells, then this is probably the problem. For example, if your data was like this:

           

          [{name:John, email:john@something},

          {name:Sarah, email:sarah@something}]

           

          Then you would have:

          <mx:DataGridColumn headerText="First Name" dataField="name"/>

          <mx:DataGridColumn headerText="Email Address" dataField="email"/>

           

          Chris

           

          • 2. Re: Datagrid component, dataprovider dependent
            artscan65 Level 1

            Thank you for your reply.

             

            Yes the dataField properties are all set. And the DG is NOT blank. Has all the records and onClick each one is well formed object with it's properties. Just SHOWS blank meaning for some reason the text boxes are like invisible!!

             

            Thank you

             

            Date: Thu, 24 Dec 2009 05:40:09 -0700

            From: forums@adobe.com

            To: artscan@msn.com

            Subject: Datagrid component, dataprovider dependent

             

            Did you set the dataField property for your pre-defined DataGridColumns to match the fields in your dataset from AMFPHP? If you are seeing blank cells, then this is probably the problem. For example, if your data was like this:

             

            [,

            ]

             

            Then you would have:

            <mx:DataGridColumn headerText="First Name" dataField="name"/>

            <mx:DataGridColumn headerText="Email Address" dataField="email"/>

             

            Chris

             

            >

            • 3. Re: Datagrid component, dataprovider dependent
              chris.huston.t10 Level 3

              Can you post your mxml code for your DataGrid and also what the data you are getting back from AMFPHP looks like? Whenever I get invisible text boxes, it is because I made a mistake in setting the dataField parameter. If there is a typo in my dataField or the dataset used different field names than I thought, I will see rows in my dataGrid that can be selected, but they will have invisible text boxes as you described. Sometimes hardcoding a small ArrayCollection for your DataProvider can help in debugging.

               

              Chris

              • 4. Re: Datagrid component, dataprovider dependent
                artscan65 Level 1

                Thank you,

                 

                Seems for some reason when data return and populate the DG it 'looses' it's column definition. Here is a work around if anyone stumbles on this at the future:

                 

                import mx.controls.dataGridClasses.DataGridColumn;

                 

                private function onRepply(arr:Array):void {

                                var ac:ArrayCollection = new ArrayCollection(arr);

                                for (var i:Number = 0; i < _formatter.length; i++) {

                                    var col:DataGridColumn = new DataGridColumn(_formatter[i].dataField);

                                    col.headerText = _formatter[i].title;

                                    col.dataField = _formatter[i].dataField;

                                    col.width = _formatter[i].width;

                                    var cols:Array = this.columns;

                                    cols.push(col);

                                    this.columns = cols;

                                }

                                this.dataProvider = ac;

                }

                 

                where:

                 

                _fields is an array holding the fields to return from database, ex. _fields = ('field1', 'field2'...)

                _formatter is an array of objects defining the columns, ex.

                 

                    <mx:Array id="formatter">

                        <mx:Object dataField="field1" title="DATE" width="100"/>

                        <mx:Object dataField="field2" title="USER" width="100"/>

                        ....

                    </mx:Array>

                 

                and you assign it to the component.

                 

                Thanks...

                 

                Mikhail Zoupas