4 Replies Latest reply on Feb 5, 2008 11:25 AM by ntsiii

    Custom ItemRenderer Problem

      I have a DataGrid that contains 10 rows of data but is only tall enough to display 5 at a time. A vertical scroll bar allows viewing any of the 10 rows. One of the columns uses a custom ItemRenderer which extends NumericStepper. I initialize the rows so that each row shows a descending number starting with 100 in the column using the ItemRender. So row 1's value is 100, row 2's is 99, row 3's is 98, etc... If I scroll to the bottom and back up, when I get back to the top the value in the column of the first row has changed from 100 to 91. If I look at the value the (overridden) ItemRenderer's set & get data functions are receiving through a debugger or through trace statements, they show 100. But the DataGrid is displaying a value that it appears to have gotten from another row.

      Would appreciate any insight as to what might be going on.
        • 1. Re: Custom ItemRenderer Problem
          GeorgeWS Level 1
          I dont know if this is the right way but im doing this :

          <mx:DataGrid id="myDataGrid" dataProvider="{theAccounts}" width="100%" height="100%" themeColor="#73B9B9">
          <mx:DataGridColumn headerText="Include" dataField="Include" width="58" sortable="false">

          <mx:HBox horizontalAlign="center">
          <mx:CheckBox click="data.Include=!data.Include" selected="{data.Include}" themeColor="#73B9B9"/>


          <mx:DataGridColumn dataField="Customer" headerText="Cust" minWidth="45" sortable="false"/>

          • 2. Re: Custom ItemRenderer Problem
            ntsiii Level 3
            Sounds like you are not handling recycling completely.

            Check the set data() function. It must either directly set the value of the stepper, or must call invalidateProperties(), and then set the stepper value in the commitProperties() override.

            • 3. Re: Custom ItemRenderer Problem
              ronowlan Level 1

              Thanks sooooo much. invalidateProperties and commitProperties fixed the problem. I was already setting the corect value in the set data() function.

              Don't know why 'cuz it seemed like all the right events and data were getting generated and handled. Just a hunch, but could the problem have had something to do with the order of events being handled? It seems possible from my debug trace statements that the dataGrid was getting repainted with data before the new data was getting set.
              • 4. Re: Custom ItemRenderer Problem
                ntsiii Level 3
                Yeah, timing of all this stuff is a bit hairy.

                Best practice, in almost all cases is to:
                In set data(): set an instance var with the data needed. Avoid doing any work here. set data can be called many times more often than you would expect. Call invalidateProperties(). this schedules a call to commitProperties to happen at the correct time.

                commitProperties(): do your UI work here.