1 Reply Latest reply on Dec 14, 2011 1:19 PM by DonMitchinson

    Auto expand Spark Datagrid rowcount with dataprovider

    DonMitchinson Level 2

      I'm having problems with a datagrid being used inside a VGroup.

       

      I've set the datagrid display to show one row + the header with the requestedRowCount = -1

      which says it should auto expand if more rows are added.

       

      When a filter is applied I reset the requestedRowCount to the number of rows + 1 (for the header).

      tracing indicates that the code is getting executed

      However the datagrid rows never change.

       

      Is this because I'm not using the properties correctly or because it's inside a VGroup?

       

      Any suggestions would be greatly appreciated... some extracted code is found below..

       

      SamlpeScreenshot.png

       

      // Filter Rentals by Job
      if (arrRentalsByJob.filterFunction == null) arrRentalsByJob.filterFunction = filterByJob;
      trace('Rentals Done');
      arrRentalsByJob.refresh();
      if (arrRentalsByJob.length == 0) {
         trace('adjusting rentals to min - num rentals = ' + arrRentalsByJob.length.toString());
         // Set the DataGrid row count to the array length, plus one for the header.                    
         dgRentalSummary.requestedRowCount = 2;
      } else {
         trace('adjusting rentals to handle num rentals = ' + arrRentalsByJob.length.toString());
         dgRentalSummary.requestedRowCount = arrRentalsByJob.length + 1;
      }
      
      dgRentalSummary.invalidateDisplayList();
      

       

       

       

      <s:DataGrid id="dgRentalSummary" width="811" height="48" dataProvider="{arrRentalsByJob}" editable="false" requestedRowCount="-1" rowHeight="20">
      <s:columns>
        <s:ArrayList>
          <s:GridColumn dataField="rentalCompany" headerText="Rental Company" width="230"></s:GridColumn>
          <s:GridColumn dataField="rentalEquipment" headerText="Rental Equipment" width="500"></s:GridColumn>
          <s:GridColumn dataField="rentalCost" headerText="Cost" labelFunction="displayHours"></s:GridColumn>
      </s:ArrayList>
      </s:columns>
      </s:DataGrid>               
      
        • 1. Re: Auto expand Spark Datagrid rowcount with dataprovider
          DonMitchinson Level 2

          Found the problem - using tip from a previous post.

           

          Can't actually set an initial "height"for the DataGrid - and I don't need to set the rowCount when I filter.

           

          So .... this now works ...

           


          // Filter Rentals by Job
          if (arrRentalsByJob.filterFunction == null) arrRentalsByJob.filterFunction = filterByJob;
          trace('Rentals Done');
          arrRentalsByJob.refresh();
          if (arrRentalsByJob.length == 0) {
             dgRentalSummary.requestedRowCount = 2;
          } else {
             dgRentalSummary.requestedRowCount = arrRentalsByJob.length + 1;
          }
          dgRentalSummary.invalidateDisplayList();

           

           

           

          <s:DataGrid id="dgRentalSummary" width="811" height="48" dataProvider="{arrRentalsByJob}" editable="false" requestedRowCount="-1" rowHeight="20">
          <s:columns>
            <s:ArrayList>
              <s:GridColumn dataField="rentalCompany" headerText="Rental Company" width="230"></s:GridColumn>
              <s:GridColumn dataField="rentalEquipment" headerText="Rental Equipment" width="500"></s:GridColumn>
              <s:GridColumn dataField="rentalCost" headerText="Cost" labelFunction="displayHours"></s:GridColumn>
          </s:ArrayList>
          </s:columns>
          </s:DataGrid>