Announcement

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

    viewstate default column width

    Hello,

    I am trying to find a way to include the default column widths in the listgrid viewstate. Take a look at the preferences example in the showcase.

    http://www.smartclient.com/smartgwt/showcase/#grid_appearance_preferences

    Save the viewstate
    Do an autofit all columns on the listgrid
    Restore the viewstate

    Notice that the columns are still autofitted, and have not been restored to their default widths.

    The width of a column is only saved in the viewstate if you have manually adjusted the width of that column. Otherwise it is null.

    I want my saved viewstate to grab the default widths of the columns when the viewport is filled, not after the autofit.

    #2
    The viewState intentionally captures the user's changes without storing off code-level defaults, in case the code-level defaults are changed, as they frequently are when new columns are added. Just make sure the code-level defaults are present when the viewState is re-applied and they will be used wherever a user-specified width has not been saved in the viewState.

    Comment


      #3
      Thank you for your reply - I have come up with a way of getting the listgrid to behave the way I want it to when I restore the viewstate.

      However, I still think it would be useful if an option existed in which the viewstate would save the width of all currently displayed columns, whether they had been adjusted by the user or not.

      Let me give you another example.

      I have a project in which the user has the option to save the current viewstate of the listgrid so that the next time they return to the page it will look exactly as they left it. By default, the listgrid fields will expand to fill all available space.

      If a user reduces the width of one of the columns, there will be a small gap on the right side of the listgrid. If that same user now saves the viewstate of the listgrid, they would expect it to appear just as they left it the next time they visit the page. However, when the page is refreshed, the grid is restored using the saved viewstate. Unfortunately, only the width of the one column that was adjusted by the user was saved, so the defaults are used for the rest of the column widths. This means that the gap, which existed when the user saved the viewstate, no longer exists because the other columns have expanded to fill the available space.

      What I want is for the viewstate to be restored to the exact state the user saved. I can use a workaround to do this by manually saving the column widths and restoring them, but it seems to me that this functionality should already be included in the listgrid viewstate.

      Comment


        #4
        Sounds like a very desirable result as resizing one column should *definitely* not lock all other columns at a particular size. After all the user could bring up the app in a much larger browser. So nothing to change here.

        Comment


          #5
          The problem we are trying to work around right now is that when the user saves the viewstate we want them to get the exact same look and feel when they return to the page.

          We have not been able to accomplish this yet.

          If what you described is the desired behavior is there a way to get the ListGrid to go ahead and resize the other columns to the size they will be right when the user resizes a column?

          I can do this by telling the ListGrid to load its own viewstate, but I don't know where to fire this and I feel like there is probably a cleaner way.

          Any help would be appreciated! Thanks in advance.

          Comment


            #6
            The viewState system is for intelligently saving only what the user has changed, as explained above. If you want a grid with certain hard coded widths just save and restore those widths with your own code rather than using viewState.

            Comment


              #7
              Thank you for the explaining the viewstate. Its use has been very helpful to us.

              We actually need exactly that, to capture what the user is doing, so we will keep using viewstate.

              One question that will help us with the one behavior we are trying to change would be if we could get the other columns to go ahead and resize right away to fill the empty space instead of waiting until we reload the viewstate.

              One way I have thought to do this would be to reload the viewstate, but I don't see what event I would use to apply this right when the user resizes.

              Is there a good way we could force the other columns to go ahead and resize at the point the user modifies a column width?

              Comment


                #8
                You don't want to do it immediately or you will "fight" with the user's attempts to resize multiple fields to be the sizes they want. In other words each time they size a field, some other field changes. So if you want the user to be able to see the final result, you might add an explicit button that applies the viewState.

                Comment


                  #9
                  I am probably not expressing our situation well enough...

                  Our goal: We are allowing the user the option to "save their layout" so that when they come back to a page it will look exactly like when they left.

                  Our current issue: When the user resizes a column they see there is empty space on the side (which is fine), they save their layout, but when they come back to the page the columns are no longer the same size as when they "saved their layout". Some would find this confusing behavior.

                  We need one of the following solutions:
                  1) When the user comes back they get the exact same column sizes as when they left (including their custom changes and any "empty space" at the end).

                  2) The columns go ahead and readjust automatically when they resize a column, leaving any columns previously adjusted as is.

                  If you have any suggestions to make either of these solutions happen we would appreciate the assistance.

                  Thanks for the help on this.

                  Comment


                    #10
                    Sorry, once again, since the screen may be a different size when restored, we see not filling space as just a strictly undesirable behavior. So if you want this, you'll need to implement as a behavior after applying viewState, or just as a save/restore behavior that doesn't involve viewState at all.

                    Comment


                      #11
                      If anyone else finds themselves in a situation where they need this capability (to make the ListGrid look exactly how it will when the viewstate is reapplied, e.g. when the user comes back to the page) here is what we came up with, but please realize as is mentioned in the posts above this is just a workaround that this is not the typical behavior/functionality.

                      You can add a listener to your ListGrid for "onFieldStateChangedEvent" and in there just make the following call to go ahead and apply the viewstate
                      Code:
                       myListGrid.setViewState(myListGrid.getViewState());
                      One way to see the effect of this... if you resize one column the others will instantly adjust (e.g. grow) to the size they will be once the viewstate is reapplied. Without this the column adjustment will not happen until the viewstate is reloaded.

                      Comment

                      Working...
                      X