7 Replies Latest reply on Sep 21, 2006 7:07 AM by ljonny18

    dataGrid + rowCount

    ljonny18 Level 1
      Hi

      I am and using a DataGrid within my Flex 2 application and I want to dynamically limit (trim) the number of rows of the data grid to the number of rows coming from / in the dataProvider (database) rather that the default 7 …


      Does anyone have any ideas on how I can do this???

      Jon.
        • 1. Re: dataGrid + rowCount
          inlineblue Level 1
          Isn't this just about changing the height of the DataGrid?
          • 2. Re: dataGrid + rowCount
            ljonny18 Level 1
            erm... I dont think so...

            I am trying to - for example.... if I only have 2 rows of data in the dataGrid, then I want to only display / include 2 rows of the datGrid (layout)...... i.e. I want to trim the amount of rows of the dataGrid to the number of rows that populate the dataGrid by the dataProvider etc...
            • 3. Re: dataGrid + rowCount
              ljonny18 Level 1
              although, I am new to Flex, so maybe missing something.... as far as I can tell, the "height" propertie of the dataGrid hyst adjusts the height displayed within the page ????
              • 4. Re: dataGrid + rowCount
                inlineblue Level 1
                We must be getting crossed up on terminology. What I mean is, for example, a DataGrid's default height is something like 156 pixels. That's enough vertical room to display the headers plus 6 rows of data. Now, if your dataprovider has only 2 rows of data, there's still going to be 4 rows worth of extra vertical space below those two data rows in the grid. To get rid of that extra space, you'll have to reduce the height of the grid, right?

                Or do you mean that you don't want the grid to paint the empty rows with alternating colours? That you just want it all to be white?
                • 5. Re: dataGrid + rowCount
                  ljonny18 Level 1
                  that right....

                  if my dataprovider has only 2 rows of data, there will still be 4 rows worth of extra vertical space in the grid below the two rows in the grid which I want to get rid of...... so then, yes you are right - I will have to reduce the height of the grid.

                  but the number of rows in the grid is not consistant (could be more than 2, could be less) depending on the dataProvider..... so I need the "height change" to by dynamic and relevent to the number of rows populated etc.

                  Jon
                  • 6. Re: dataGrid + rowCount
                    inlineblue Level 1
                    Then your only choice is to do a little math whenever you set the dataprovider. Get the number of rows, multiply by the number of pixels per row and set the grid's height to be that. Of course, you'll most likely have to put a max on the height as you can't just let the grid grow indefinitely.

                    Really, my advice would be to not bother. Having a grid that might be taller than the number of displayed rows is perfectly acceptable UI practice.
                    • 7. Re: dataGrid + rowCount
                      ljonny18 Level 1
                      ok - thanks for your help inlineblue ... I understand what you are saying and dont think will bother trimming the datagrid.....

                      the only reason I asked was because eventually I want to allow the user to "add" a row to the DataGrid, and was thinking of including an "Add Row" button etc... allowing them to add a row, therefore trimming the dataGrid accordingly and adding an additional row to the bottom of the dataGrid when the button is selected.