Announcement

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

    Column width not updating in ViewState after upgrading to SmartGWT 13.1 (worked in 11.1)

    Hi Team,

    We are facing an issue after upgrading our application from SmartGWT 11.1 to 13.1.
    In 11.1, whenever a user changed a column width through UI customization, the updated width was correctly captured in the grid’s viewState. After upgrading to 13.1, this no longer works — the column width updates are not being reflected in the viewState.

    To confirm this, we created a very simple isolated test case.
    In SmartGWT 11.1, the getViewState() output includes the updated column widths.
    In SmartGWT 13.1, the same code does not include the updated widths — the width changes are not recorded in the viewState at all.

    Attaching console logs below showing the difference in behavior between 11.1 and 13.1.

    11.1 version Click image for larger version

Name:	11.1_consolelogs_viewstate.png.png
Views:	14
Size:	291.3 KB
ID:	276821

    13.1 version
    Click image for larger version

Name:	13.1_consolelogs_viewstate.png
Views:	15
Size:	50.9 KB
ID:	276822 Below is the exact test class we used to reproduce the issue:


    package com.i2.tm.ui.ria.client.lbp.util;
    import com.smartgwt.client.widgets.Window;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.layout.VLayout;
    import com.smartgwt.client.widgets.Button;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.util.SC;

    public class SmartGWTWidthTestWindow {
    private static Window testWindow;
    private static ListGrid testGrid;
    public static void show() {
    if (testWindow != null && testWindow.isDrawn()) {
    testWindow.bringToFront();
    return;
    }
    createWindow();
    testWindow.show();
    }
    private static void createWindow() {
    testWindow = new Window();
    testWindow.setTitle("Width Persistence Test - 4 Fields");
    testWindow.setWidth(600);
    testWindow.setHeight(400);
    testWindow.setAutoCenter(true);
    testWindow.setIsModal(true);
    VLayout layout = new VLayout();
    layout.setWidth100();
    layout.setHeight100();
    layout.setPadding(10);
    // Simple 4-field grid
    testGrid = new ListGrid();
    testGrid.setWidth100();
    testGrid.setHeight(150);
    // 4 fields with initial widths
    testGrid.setFields(
    new ListGridField("field1", "Field 1") {{ setWidth(100); }},
    new ListGridField("field2", "Field 2") {{ setWidth(120); }},
    new ListGridField("field3", "Field 3") {{ setWidth(80); }},
    new ListGridField("field4", "Field 4") {{ setWidth(150); }}
    );
    // Sample data
    Record record = new Record();
    record.setAttribute("field1", "Data 1");
    record.setAttribute("field2", "Data 2");
    record.setAttribute("field3", "Data 3");
    record.setAttribute("field4", "Data 4");
    testGrid.setData(new Record[]{record});
    layout.addMember(testGrid);
    // Test button
    Button testButton = new Button("Test Width Persistence");
    testButton.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
    testWidthPersistence();
    }
    });
    layout.addMember(testButton);
    testWindow.addItem(layout);
    }
    private static void testWidthPersistence() {
    // Get viewState BEFORE width change
    String before = testGrid.getViewState();
    SC.logWarn("BEFORE: " + (before != null ? before : "null"));
    ListGridField[] fields = testGrid.getFields();
    fields[0].setWidth(150);
    fields[1].setWidth(200);
    fields[2].setWidth(60);
    fields[3].setWidth(100);
    testGrid.setFields(fields);
    // Get viewState AFTER width change
    String after = testGrid.getViewState();
    SC.logWarn("AFTER: " + (after != null ? after : "null"));
    SC.say("Check console - ViewState should contain width info after change!");
    }
    }
    Attached Files

    #2
    viewState is intended to capture the end user's changes to the ListGrid (through resizing, for example). It is, by design, not intended to capture either the initial settings, or programmatic changes.

    This is because, if viewState captures initial settings or programmatic changes, then if you make changes to your grid, like add a new field and adjust the default widths, then the viewState of every end user is just going to force the old developer-supplied settings, leading to horizontal overflow in this case.

    Indeed, you have the same kinds of problems if you just view the same grid later on a narrow browser.

    So, you are seeing the system working as designed - ignoring programmatic changes. This is how viewState works in all supported versions, and how it has to work for it to make any sense.

    In 11.1, you are seeing a bug that was corrected after 11.1 went end-of-life.

    Speaking of that, why are you upgrading to 13.1 when 14.x releases are out? If you're going to do an upgrade, you should always pick the latest production release, otherwise you're just setting yourself up to have to do another upgrade sooner.

    Comment


      #3
      Thank you for a quick response. We've been using this approach since version 3.1 - long time ago.
      We have a requirement of saving and recreating column width decisions users made (via resizing) - so they do not need to do that over and over again when they open same grid.
      Is there an alternative way to achieve this?

      Thank you!

      Comment


        #4
        As we just explained, that's exactly what viewState does. You can see that in the Showcase.

        The problem is, your test case makes programmatic changes to the column width. Those are not persisted, by design, for the reasons we explain above.

        Comment

        Working...
        X