6 Replies Latest reply on Jun 8, 2010 11:40 AM by Flex harUI

    DataGrid "validation" of *all* item renderers

    Ansury Level 3

      Rather complex problem here, hopefully someone here can jog my deadlocked cpu (brain) for a creative solution.


      I need to validate editable datagrid fields for a column of data.  To do the validation (not using a validator here), the previous row's value is needed (not a major problem in itself).  But on top of that, since the validity of each row is dependent on the values of neighboring rows, it's possible to change the 'current' row to a valid value which makes other row values invalid in the process.


      To put the problem more simply, I need to provide row-by-row error feedback to ensure that the value for each row is higher than the previous row's value.  Any row value can by changed by the user at any time (a change to the first row could even invalidate all rows after it).  For now I just want to change the color of the item renderer/editor's text for all invalid rows to red text as the user types into an item editor (or at least when they exit the editor).


      Is there a way to access the item renderers for all rows of a DataGrid if you have access to the DataGrid reference?  If I could simply call a function for "each renderer" in response to a change event, I'd be good to go.  (But I'd imagine each row 'shares' a renderer object via a factory so there is no actual "list" to iterate over...arg.)  Ideas?

        • 1. Re: DataGrid "validation" of *all* item renderers
          Flex harUI Adobe Employee

          I think you want to examine the dataProvider's rows, not the neighboring

          renderers.  When you change any data in the dataProvider, all rows are

          refreshed so as long as the renderer can do its validity calculation on

          refresh by examining the dataProvider rows, it should be doable.

          • 2. Re: DataGrid "validation" of *all* item renderers
            Ansury Level 3

            Sure I can do that, but is there a way to force the renderers to 'update' the view so that the invalid fields are flagged (i.e. color style change)?

            • 3. Re: DataGrid "validation" of *all* item renderers

              I have a similar problem with the List component, but for AdvancedDataGrid I solved the problem with this function:


              public function invalidatePropertiesOnRenderers():void {
                      for each ( var rendererArray:Array in listItems )
                          for each ( var renderer:Object in rendererArray)
                              if( renderer is UIComponent)
                                  (renderer as UIComponent).invalidateProperties();


              I added that to my custom extension of AdvancedDataGrid and call it externally when I need to force all my renderers to update. I would assume this could be considered a rather costly method to execute though - so maybe keep that in mind.

              • 4. Re: DataGrid "validation" of *all* item renderers
                Flex harUI Adobe Employee

                Each renderer should examine its data property and get the DataGrid(owner)

                property and determine its rowIndex, do the calculation to determine if it

                is valid, then draw itself with the appropriate color.

                • 5. Re: DataGrid "validation" of *all* item renderers
                  Ansury Level 3

                  I'm already doing that, the problem is getting that validation to happen for all renderers when one renderer's value changes.


                  I don't think invalidateProperties() helps (possibly because this is just a DataGrid?), first it only gets called on the active renderer (not all the others like I need) and second even if it did, I'm fairly sure the 'data' value isn't going to be set at that time.


                  The design used for DataGrid editors/renderers seems to be needlessly complicating this seemingly simple task.  I can't remember the last time I've had such a frustrating experience with a Flex component.



                  To top it off I have other issues disabling edits on specific rows for a different DataGrid.  The event.preventDefault() responses posted all over the Internet as the "solution" seem to neglect the fact that it's still possible to edit the fields if you click/drag the mouse to select text in a field and type while still holding the mouse button down (thus replacing the 'selected' text).  Ugh!  Only solution seems to be finding a way to manually revert back to the previous value.


                  I'm starting to think DataGrid editors just flat out suck in general as far as flexibility.

                  • 6. Re: DataGrid "validation" of *all* item renderers
                    Flex harUI Adobe Employee

                    InvalidateList() should force a redraw of every renderer, but so will any

                    dataprovider change.


                    3.5 contains more fixes for the drag-select text and edit issue.