22 Replies Latest reply on Aug 29, 2011 7:48 AM by Claudiu Ursica

    ItemRenderer data not updated

    diana.c10

      Hi all,

       

      We are facing an issue with an item renderer we use to display an image in a datagrid. We want to display different images depending on the object's type.

       

      The problem is that if we replace the objects from the data grid's provider array the value for the item renderere remains the same as we set it the first time.

       

      Do you have some suggestions on this?

       

      Thanks,

        • 1. Re: ItemRenderer data not updated
          Amy Blankenship Level 4

          What code do you have in the renderer that sets the image based on the data?

          • 2. Re: ItemRenderer data not updated
            diana.c10 Level 1

            [Bindable] override public function set data(myData:Object):void {

                stepicon.source = myData.image

                super.data = myData

            }

             

            and the image object

            <mx:Image height="16" width="16"  id="stepicon"/>

             

            I have checked and the image field gets updated correctly .... but the method is never called when the objects are updated

            • 3. Re: ItemRenderer data not updated
              Amy Blankenship Level 4

              Right.  The set data function only changes when the entire data object changes.  The quickest way for you to resolve this is to just bind stepIcon.source to {data.stepImage}.  The second quickest way is to call itemUpdated on the collection when you change the field.

              • 4. Re: ItemRenderer data not updated
                Don Kerr

                Sounds like you might need dp.refresh() after updating the arrayCollection.

                • 5. Re: ItemRenderer data not updated
                  diana.c10 Level 1

                  I tried both refresh() and itemUpdated() and neither works. Do you have any other suggestions ?

                   

                  Thanks

                  • 6. Re: ItemRenderer data not updated
                    diana.c10 Level 1

                    Another example would be using <mx:Text text="{data.type}"/> -- this does not work as well when data in the data grid gets updated.

                    • 7. Re: ItemRenderer data not updated
                      Amy Blankenship Level 4

                      Please post the code you're using that calls refresh() and/or itemUpdated()

                      • 8. Re: ItemRenderer data not updated
                        diana.c10 Level 1

                        <mx:DataGrid id="resultsGrid"  dataProvider="{results}">

                        <mx:DataGridColumn headerText="Status" dataField="icon"
                                                                   itemRenderer="ItemRenderer" rendererIsEditor="true"/>

                        </mx:DataGrid>

                         

                        and the ItemRenderer

                         

                        <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"
                            width="100%" height="100%" minWidth="16" maxWidth="25"
                            horizontalAlign="center" verticalAlign="middle">

                        <mx:Text text="{data.text}"/>
                        </mx:HBox>

                         

                        when I modify the results I clear all existing items and after I add one:

                         

                        results.addItem(item);
                        results.itemUpdated(results.getItemAt(results.length - 1 ));

                         

                        var arr:ArrayCollection = resultsGrid.dataProvider as ArrayCollection;
                        arr.refresh();
                        resultsGrid.invalidateDisplayList();
                        resultsGrid.invalidateList();

                        • 9. Re: ItemRenderer data not updated
                          diana.c10 Level 1

                          Do you have any other suggestions ?

                          • 10. Re: ItemRenderer data not updated
                            Francisc Level 3

                            Does the new dataProvider have images?

                            If not you have to set it to null or otherwise remove it in the overriden method.

                            • 11. Re: ItemRenderer data not updated
                              diana.c10 Level 1

                              yes, it does. And it also has some tool tips which are also not refreshed.

                              • 12. Re: ItemRenderer data not updated
                                Amy Blankenship Level 4

                                Can you post the entire contents of the method, including the part where you say you are clearing all existing items?

                                • 13. Re: ItemRenderer data not updated
                                  diana.c10 Level 1

                                  So I have the following data grid:

                                   

                                  <mx:DataGrid id="resultsGrid" width="100%" height="200" dataProvider="{results}">

                                  <mx:columns>
                                                      <mx:DataGridColumn headerText="Status" dataField="icon"
                                                                             itemRenderer="com.hp.bsa.renderers.ObjectIconRenderer" rendererIsEditor="true"/>
                                                      </mx:columns>

                                  </mx:DataGrid>

                                   

                                  ObjectIconRenderer:

                                   

                                  <?xml version="1.0" encoding="utf-8"?>
                                  <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml">
                                      <mx:Script><![CDATA[
                                         
                                          [Bindable] override public function set data(step:Object):void {
                                              si.source = "image.png"
                                              super.data = step;
                                          }   
                                         
                                         
                                      ]]></mx:Script>
                                      <mx:Image height="16" width="16" toolTip="{data.tooltip}" id="si"/>
                                  </mx:HBox>

                                   

                                  And the method that does the update:

                                   

                                  private function updateResults(updatedResults:ArrayCollection):void {
                                      results.removeAll();
                                             
                                      for (var obj:Object in updatedResults) {

                                          var item:Object = new Object();

                                          item.tooltip = obj.tooltip;

                                          results.addItem(item);
                                      }       
                                           
                                             
                                       var arr:ArrayCollection = resultsGrid.dataProvider as ArrayCollection;
                                        arr.refresh();
                                              resultsGrid.invalidateDisplayList();
                                              resultsGrid.invalidateList();
                                  }

                                  • 14. Re: ItemRenderer data not updated
                                    Francisc Level 3

                                    I'm not sure this belongs in the override data method: si.source = "image.png"

                                    Who is si? Also, missing semicolon at end.

                                    • 15. Re: ItemRenderer data not updated
                                      Claudiu Ursica Level 4

                                      You are parsing into plain objects which are not IEventDispathcer-s by default therefore they will not be able to dispatch change events. You might be getting the collection events but not the item updates event's hence the lack of update inside the tooltip. Try to go with ObjectProxy or a custom Bindable class instead of simple Object.

                                       

                                      for (var obj:Object in updatedResults) {

                                              var item:Object = new Object(); <-- use custom type or wrap in ObjectProxy here (Though if you only need a string it might work with passing a simple string)

                                             item.tooltip = obj.tooltip;

                                              results.addItem(item);

                                          }       

                                       

                                      HTH,

                                      C

                                      • 16. Re: ItemRenderer data not updated
                                        diana.c10 Level 1

                                        One step further :) by using the ObjectProxy the tooltip is being updated but the image not. Do you have any other suggestions?

                                        • 17. Re: ItemRenderer data not updated
                                          Claudiu Ursica Level 4

                                          This is because you are not passing an image reference along with the data or the source of the image, share the code related to the image ...

                                           

                                          C

                                          • 18. Re: ItemRenderer data not updated
                                            diana.c10 Level 1

                                            <mx:DataGrid id="resultsGrid" width="100%" height="200" dataProvider="{results}">

                                            <mx:columns>
                                                                <mx:DataGridColumn headerText="Status" dataField="icon"
                                                                                       itemRenderer="com.hp.bsa.renderers.ObjectIconRenderer" rendererIsEditor="true"/>
                                                                </mx:columns>

                                            </mx:DataGrid>

                                             

                                            I have here the object renderer:

                                             

                                            <?xml version="1.0" encoding="utf-8"?>
                                            <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml">
                                                <mx:Script><![CDATA[
                                                   
                                                    [Bindable] override public function set data(step:Object):void {

                                                        var type:Dictionary = new Dictionary();

                                                        type['a'] = 'a.png';

                                                        type['b] = 'c.png';
                                                        si.source = type[step.tooltip];
                                                        super.data = step;
                                                    }   
                                                   
                                                   
                                                ]]></mx:Script>
                                                <mx:Image height="16" width="16" toolTip="{data.tooltip}" id="si"/>
                                            </mx:HBox>

                                             

                                            I started in debug mode and the code never gets executed on update

                                            • 19. Re: ItemRenderer data not updated
                                              Amy Blankenship Level 4

                                              try replacing the contents of updateResults with

                                               

                                              resultsGrid.dataProvider = updatedResults;

                                               

                                              HTH;

                                               

                                              Amy

                                              • 20. Re: ItemRenderer data not updated
                                                Claudiu Ursica Level 4

                                                Am I reading this correct?

                                                you have the path to the image inside tooltip?

                                                 

                                                if so this should work

                                                 

                                                <mx:Image height="16" width="16" toolTip="{data.tooltip}" id="si" source={data.tooltip}/>

                                                 

                                                I am not sure what is your use-case though, your code confuses me a little bit.

                                                 

                                                 

                                                presumably you ant to display an image and update a tooltip in datagrid

                                                 

                                                 

                                                i would go like this is a little cleaner and easier to read:

                                                 

                                                 

                                                class ImageData

                                                {

                                                    public var tooltipString:String;

                                                    public var imagePath:String

                                                 

                                                }

                                                 

                                                 

                                                private function updateResults(updatedResults:ArrayCollection):void {

                                                    results.removeAll();

                                                 

                                                  for (var obj:Object in updatedResults) {

                                                        var item:ImageData = new ImageData();

                                                        item.tooltipString = obj.tooltip;

                                                        item.imagePath = obj.

                                                Sent: Monday, August 29, 2011 4:19 PM

                                                Subject: Re: ItemRenderer data not updated

                                                 

                                                 

                                                <mx:DataGrid id="resultsGrid" width="100%" height="200" dataProvider="">

                                                <mx:columns>

                                                                    <mx:DataGridColumn headerText="Status" dataField="icon"

                                                                                           itemRenderer="com.hp.bsa.renderers.ObjectIconRenderer" rendererIsEditor="true"/>

                                                                    </mx:columns>

                                                </mx:DataGrid>

                                                 

                                                I have here the object renderer:

                                                 

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

                                                <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml">

                                                    <mx:Script><![CDATA[

                                                       

                                                        override public function set data(step:Object):void {

                                                            var type:Dictionary = new Dictionary();

                                                            type['a'] = 'a.png';

                                                            type['b] = 'c.png';

                                                            si.source = type[step.tooltip];

                                                            super.data = step;

                                                        }   

                                                       

                                                       

                                                    ]]></mx:Script>

                                                    <mx:Image height="16" width="16" toolTip="{data.tooltip}" id="si"/>

                                                </mx:HBox>

                                                 

                                                I started in debug mode and the code never gets executed on update

                                                • 21. Re: ItemRenderer data not updated
                                                  diana.c10 Level 1

                                                  The path is mapped in a dictionary. dictionary[tooltip] = path to image. it still does not work even after setting the dataProvider.

                                                  • 22. Re: ItemRenderer data not updated
                                                    Claudiu Ursica Level 4

                                                    There is obviously a flaw in your logic, you need to debug and find out, I don;t exactly know what are your requirements so I only answer based on my assumption from what I can read from your code snippets, even if I manage to give you a hint or something does not mean is the best way to go about it it will work at it's best ... 

                                                     

                                                    if your code is clean and path's are correct a simple population of the result array collection should update the datagrid through bindings ...

                                                     

                                                    C