Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How to set fixed width of column in List Grid.

    How I can set fixed width of column in ListGrid.

    #2
    Set the widths on the ListGridFields and set ListGrid.setCanResizeFields(false).

    Sanjiv

    Comment


      #3
      Sanjiv,

      I have posted many times about my frustration with getting ListGridField.setWidths() to work without getting any response from the community.

      Would you please expand more about why ListGrid.setCanResizeField(false) is necessary? This was not obvious to me and I have not seen where this requirement is documented.

      If setWidths is does nothing when setCanResizeField() is not properly set - should the devoper console not also emit some kind of warning?

      Comment


        #4
        Follow-up

        Sanjiv,

        Further to my previous post, here is the javadoc comment for ListGridField.setWidth().

        Code:
        The width of this field, specified as either an absolute number of pixels, a percentage of the remaining space, or "*" to allocate an equal portion of the remaining space. 
        ListGrid field widths may also be set when the fields are instantiated via the listGrid.setFields() method by passing an array of numbers (absolute pixel sizes only) as the second parameter
        Parameters:
        width width Default value is "*"
        It does not provide any detail about how to set the input parameter to get pixel and percentage width setting, furthermore if you look at the setWidth(int) version you will see the javadoc is exactly the same. I have no clue how an integer parameter could be used to specify pixel *OR* percentage widths for this.

        BTW: I tried setting ListGrid.canResizeField(false) and it still has no effect on my code. All field widths within my grid continue to be evenly spaced.

        IMO being able to set widths like this is very important for commercial applications that tend to deal with a lot more attributes than the simple sample programs. Autowidths are great only for simple apps.

        Comment


          #5
          There are two setWidth methods. One takes a String which I believe allows you to specify pixels, percentages or equal size e.g. "76px", "50%", "*". The other method takes an int, which I believe is pixels. As you say the javadoc description for both methods are the same which is a bit confusing.

          Comment


            #6
            Thank You!!!

            Thanks colleagues. I fix problem. Thank You very much!

            Comment


              #7
              Thanks Dazza, unfortunately no matter what I set the setWidths value to, it has no effect on my program - The quality of the Javadoc is pretty frustrating.

              There appear to be a lot of api methods that are sequense/context dependent that are not well spelled out.

              My first impression of the product was very positive but I am finding the learning curve and lack of support pretty depressing.

              Yes it is ungratious to complain about something that is free - but my time is not free and why would anybody even consider paying good money for a product when the initial impression is so poor.

              Comment


                #8
                @toggle57 The suggestion to setCanResizeField() was related to another user's question regarding making a field not resizable. It does not apply to you.

                To adjust the width of a field after draw use resizeField. However unless you have a specific reason to set this after draw, you should instead make sure that the fields definitions you provide before drawing have the sizes you want.

                Comment


                  #9
                  Thank you for responding.

                  I have tried using setWidth *both* before and after drawing - as I have noticed that this is sometimes significant, however this has done nothing for me.

                  My goal is to set field widths on my databound grid prior to drawing as a percentage of the total grid width so that they will all proportionaly expand and contract when the grids containing widget is resized.

                  What has not been clear to me is the relationship between ListGridField and Datasource objects... I see that ListGrid and ListGridField are "View" related and Datasource is "Model" related however it is also clear the Datasource blurs this distinction because one can create an application with Datasource alone - and even retrieve ListGridField objects out of that Datasource that we never explicitly created.

                  However... if one retrieves these Datasource created ListGridFields and attempts to setWidth on them nothing happens.

                  As a result I examined the MiniApp sample and saw that both were created (ListGridFields and DataSource field types) - I have now copied this in my application and am now able to set width on my grid.

                  Perhaps this is working as designed... but it was really not clear (at least to me).

                  I was also really hoping that setting widths via "em" increments would be possible. Percentages work but I think relative sizing based on field character width would be easier and more accurate.

                  It would also be nice to set a minimum field width equal to the width of the Heading so that they do not get chopped off when resized - also not allowing the containing grid to be resized less then the minimum width of the sum of the column widths would be a nice automatic setting. Perhaps this is already possible... I am still learning the api.
                  Last edited by toggle57; 29 Nov 2009, 09:49.

                  Comment


                    #10
                    Try posting a minimal test case of what you're describing.

                    On DataSource fields vs ListGrid fields - this is called model-driven development.

                    Comment


                      #11
                      width of the cell to width of the title or header

                      1.How to set the width of the cell to the width of the title in smartclient ,listgrid?

                      I am using listgrid and restdatasource.

                      2.How to get horizontal scroll bar for listgrid ,i am fetching 50 records and vertical scroll bar is appearing .All my columns are fitting to the size of the grid.I need horizontal scroll bars as I have more than 20 columns?

                      Comment


                        #12
                        I have a ListGrid backed by a datasource. The datasource fields are fine but I need to set the widths. By default it seems the field columns are just spaced evenly.

                        In onDraw it seems I can successfully call hideField, reorderField, etc, but resizeField has no effect. Should it?

                        Otherwise I guess the answer is to create new, nearly identical, ListGridFields to override the datasource fields, and then call setFields. That just seemed heavyweight.

                        Comment


                          #13
                          Seems like there are a lot of questions in this thread. In short:

                          - ListGridFields can be initialized with a width specified as "*" or a percentage value by calling someField.setWidth("*"); -- or with an integer pixel width via someField.setWidth(50);

                          - resizeField should work to resize a listGrid's field after it has been initialized (at runtime) -- if this isn't working for people in any circumstances, please post a test case we can use to see the problem.

                          - You can have fields fit to their content or title via the listGrid.setAutoFitFieldWidths() or listGridField.setAutoFitWidth()

                          - horizontal scrollbars appear when they are necessary -- IE: when thewidth of all the fields is wider than the ListGrid's specified size.

                          Comment


                            #14
                            Thanks very much for the reply. I agree that new ListGridFields set for the ListGrid do seem to behave as expected. My question has more to do with trying to manipulate the "default" ListGridFields that were defined as DataSourceFields in the underlying DataSource (set by ListGrid.setDataSource(ds)).

                            Those fields can be accessed as ListGridFields but seem not to respond to any resizing. Is that to be expected?

                            Comment


                              #15
                              Yes, think of the auto-generated fields as a read-only view - the intended API for specifying additional properies is to provide fields to the grid. See the QuickStart Guide chapter on DataBinding for more information. See also the resizeField() API for resizing after the component is drawn.

                              Comment

                              Working...
                              X