Announcement

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

    Restoring default column widths

    When the user opens a grid for the first time, all "preferences" are great (column widths). If the user changes a column size, we want to be able to give him the option to revert to the default. Is there a way to do this?

    I'd like to illustrate the problem on the current smartgwt 4.1 showcase:

    Starting with "grid->appearance->preferences":
    http://www.smartclient.com/smartgwt/...ce_preferences

    Resize "capital" to the minimal allowed width (the text will became "..." both in title and in values).

    Choose the default viewState and click "restore view state".

    Result: the "capital" column is still "...".
    Expected result: the layout as if the client reloads the application.

    P.S. This is very similar to: http://forums.smartclient.com/showth...iewstate+width (not the same though - we don't want a fixed width solution, we want the perfectly working "default" behavior, before the user resizes anything)
    Last edited by ispasov; 8 Aug 2014, 01:58. Reason: link to a similar issue

    #2
    The best we have is setFields(getDefaultFields), but we are not sure if this is the correct approach.

    Comment


      #3
      Memorize grid's state just after it is drawn using ListGrid.getViewState(), and then, when user request revert, call setViewState(viewState).
      MichalG

      Comment


        #4
        Originally posted by michalg View Post
        Memorize grid's state just after it is drawn using ListGrid.getViewState(), and then, when user request revert, call setViewState(viewState).
        MichalG
        This won't restore widths to their initial values. The getViewState returns width:null for "Capitals". After this user changes it to "10" and any calls to setViewState with "width:null" are not going to change the "10".

        Comment


          #5
          Call ListGrid.autoFitFields()

          Comment


            #6
            Originally posted by Isomorphic View Post
            Call ListGrid.autoFitFields()
            Hi, thanks for the response.
            We are probably talking about ListGrid.autoFitFields(ListGridField[]), which we tried as grid.autoFitFields(grid.getFields()).
            This method behaves strangely - when I call it twice (like the user presses "load system defaults" twice, the result is different. The only thing that works for us is setFields(getDefaultFields), but it just does not seem clean.

            Note: (we are working with smartgwt 3.1p)

            Comment


              #7
              Hi ispasov,

              please see these threads, perhaps they'll help.

              Best regards,
              Blama
              Last edited by Blama; 8 Aug 2014, 03:53. Reason: typo

              Comment


                #8
                You could also specify initial widths of "*" for all fields - those values would be expected to be reapplied by setViewState()

                Comment


                  #9
                  Originally posted by Blama View Post
                  Hi ispasov,

                  please see these threads, perhaps they help.

                  Best regards,
                  Blama
                  Thank you Blama, this confirms my approach. I will copy the answer from your thread here, to help future users.

                  Originally posted by Isomorphic View Post
                  We don't have an API to reset the field widths to whatever they were when the ListGrid was first rendered.
                  The easiest way to achieve this in application code is probably to use setFields() to re-apply the initial fields array in your application code.
                  This will then re-evaluate how the default specified widths (whether an explicit number or unset / "*") should be translated to actual sizes.

                  Comment

                  Working...
                  X