4 Replies Latest reply on Aug 20, 2007 9:16 AM by Newsgroup_User

    DataGrid : hide column : possible?

    stephan.k
      Dear Forum

      I'd like to hide a column in a datagrid? I'm getting ID's from the database that the user doesn't need to see but that are necessary to communicate back with the database. I'm using the dataGrid component to list the content.

      Is it possible to hide the ID column in the dataGrid? I've tried setting the width to 0 without luck. Also the visible parameter doesn't seem to compile. I've attached a snippet of the code.

      Any help appreciated.

      Thank you very much

      SK
        • 1. Re: DataGrid : hide column : possible?
          Level 7
          Don't set the width to 0, instead just don't add the data to the grid.
          Before setting the grid's dataProvider, set your columns like so:

          var ord:DataGridColumn = new DataGridColumn("Order");
          ord.width = 40;
          ord.headerText = "Order:";
          myGrid.addColumn(ord);


          new DataGridColumn("Order");

          When you make the new column the field name should match that being returned
          from the database.

          So, you'll have a group of these statements, that set the columns in your
          grid. Columns in the dataProvider that don't match are simply not displayed.
          Yet you can still get any columns in the dataProvider:
          trace(myGrid.selectedItem.id)...

          HTH

          --
          Dave -
          Head Developer
          http://www.blurredistinction.com
          Adobe Community Expert
          http://www.adobe.com/communities/experts/


          • 2. Re: DataGrid : hide column : possible?
            Level 7
            A simple approach I have used in the past does involve setting a column
            width to zero... only completely hides if you also set the columns
            "resizeable" property to false as well...

            dg.getColumnAt(i).resizable = false;

            (F8)

            stephan.k wrote:
            > Dear Forum
            >
            > I'd like to hide a column in a datagrid? I'm getting ID's from the database
            > that the user doesn't need to see but that are necessary to communicate back
            > with the database. I'm using the dataGrid component to list the content.
            >
            > Is it possible to hide the ID column in the dataGrid? I've tried setting the
            > width to 0 without luck. Also the visible parameter doesn't seem to compile.
            > I've attached a snippet of the code.
            >
            > Any help appreciated.
            >
            > Thank you very much
            >
            > SK
            >
            > var dgCol_order:DataGridColumn = dg.addColumn("Order");
            > var dgCol_cat:DataGridColumn = dg.addColumn("Category");
            > var dgCol_sess:DataGridColumn = dg.addColumn("SessionID");
            > dg.getColumnAt(0).width = 0;
            > dg.getColumnAt(1).width = 200;
            > dg.getColumnAt(2).width = 0;
            > dgCol_order.visible = false;
            > dgCol_sess.visible = false;
            >
            • 3. Re: DataGrid : hide column : possible?
              stephan.k Level 1
              Thank you to both of you.

              I've followed your advice and didn't even display the data in the set but I've added it to the dataprovider. When I select the row I can retrieve the data with myGrid.selectedItem.id. Works perfectly!

              Thanks again

              Cheers

              SK
              • 4. Re: DataGrid : hide column : possible?
                Level 7
                you're welcome...

                stephan.k wrote:
                > Thank you to both of you.
                >
                > I've followed your advice and didn't even display the data in the set but I've
                > added it to the dataprovider. When I select the row I can retrieve the data
                > with myGrid.selectedItem.id. Works perfectly!
                >
                > Thanks again
                >
                > Cheers
                >
                > SK
                >