5 Replies Latest reply on Jul 4, 2008 11:15 PM by Gregory Lafrance

    datagrid has unwanted extra empty rows

    toSoarAgain
      I initialize a datagrid control, also printdatagrid, with an ArrayCollection data provider with, say, 2 rows. Yet the table as it appears sports a number of irksome extra rows, all empty. What can I do to suppress this unwanted behavior.
        • 1. Re: datagrid has unwanted extra empty rows
          Gregory Lafrance Level 6
          rowCount="2"

          You may need to write code so this is populated with the number of rows in the dataProvider.
          • 2. Re: datagrid has unwanted extra empty rows
            toSoarAgain Level 1
            Upon closer inspection this technique did not work. According to earlier posts, it appears that the number of rows is dictated by the (default or explicit) height of the grid. To eliminate empty rows one needs to add the rows heights for rows containing data, and the header height, and set the grid height to the result. This is tedious to put it mildly, especially when row heights vary.
            Flex does provide a function that should do the job, but for the inexplicable presence of argument hh (see below)
            hh:Number — The current height of the row. ???????
            If I knw this value why would I call the function????
            Could someone kindly shed light on this?


            calculateRowHeight () method

            protected function calculateRowHeight(data:Object, hh:Number, skipVisible:Boolean = false):Number

            Calculates the row height of columns in a row. If skipVisible is true> the DataGridBase already knows the height of the renderers for the column that do fit in the display area so this method only needs to calculate for the item renderers that would exist if other columns in that row were in the display area. This is needed so that if the user scrolls horizontally, the height of the row does not adjust as different columns appear and disappear.

            Parameters data:Object — The data provider item for the row.

            hh:Number — The current height of the row.

            skipVisible:Boolean (default = false) — If true, no need to measure item renderers in visible columns



            Returns Number — The row height, in pixels.

            • 3. Re: datagrid has unwanted extra empty rows
              toSoarAgain Level 1
              The saga continues....
              I discovered protected datagrid method sumRowHeights, and thought this might do the trick. It was not to be, as I got

              Error #1009: Cannot access a property or method of a null object reference.

              for my pains.

              The offending code is at line
              trace("Calculated height = "+super.sumRowHeights(0,qtyRows));

              of
              <!-- Custom control for the printed page. -->
              <mx:DataGrid xmlns:mx=" http://www.adobe.com/2006/mxml" width="100%"
              variableRowHeight="true" styleName="gridTablePrintStyle" >
              <mx:Script>
              <![CDATA[
              import mx.collections.ArrayCollection;
              import mx.resources.ResourceManager;

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


              var qtyRows:int=ArrayCollection(data).length;
              super.dataProvider=data;
              trace("qtyRows = "+qtyRows);
              trace("Default height = "+super.height);

              //super.height=this.sumRowHeights(0,ArrayCollection(data).length);
              trace("Calculated height = "+super.sumRowHeights(0,qtyRows));

              }
              ]]>
              </mx:Script>
              <mx:columns>
              <mx:DataGridColumn dataField="name" headerText="@Resource(key='attributeName', bundle='WidgetLabels')" width="150">
              <mx:itemRenderer>
              <mx:Component>
              <mx:Text styleName="gridTableTextPrintStyle"
              width="100%"
              selectable="false"
              text="{data.name}" />
              </mx:Component>
              </mx:itemRenderer>
              </mx:DataGridColumn>
              <mx:DataGridColumn dataField="value" headerText="@Resource(key='attributeValue', bundle='WidgetLabels')">
              <mx:itemRenderer>
              <mx:Component>
              <mx:Text styleName="gridTableTextPrintStyle"
              width="100%"
              selectable="false"
              text="{data.value}"/>
              </mx:Component>
              </mx:itemRenderer>
              </mx:DataGridColumn>
              </mx:columns>
              </mx:DataGrid>
              • 4. Re: datagrid has unwanted extra empty rows
                Gregory Lafrance Level 6
                Maybe I don't understand what you want to do, but in this code rowCount seems to work:
                • 5. Re: datagrid has unwanted extra empty rows
                  Gregory Lafrance Level 6
                  Actually to see what you describe you need to delete all but 2 <employee> records in SampleData.xml.