vaadin / framework

Vaadin 6, 7, 8 is a Java framework for modern Java web applications.
http://vaadin.com/
Other
1.79k stars 729 forks source link

Table.setSortContainerPropertyId() shrinks column width to minimum #4678

Closed vaadin-bot closed 10 years ago

vaadin-bot commented 10 years ago

Originally by lohmann@zad-northeim.de


See https://vaadin.com/pro/support#362 based on https://vaadin.com/forum#!/thread/4308279

I have a table which uses autosizing of all columns (no explicit setWidth()) and it shows up like expected. The colums are either sized after column header or column content, based on which is wider than the other. This is what I want. But as soon as I set Table.setSortContainerPropertyId(acolumn) the specified column (and only that one) gets resized to the column content. Even if the header is much wider than the column content. Much worse: it should be even larger with the sort order indicator.

The browser does not matter as it doesn't seem to be a rendering issue. The header's element style gets set (for example) to 150px when no ordering takes place.

It gets set to 46px when ordering takes place: . Just to make sure: If you do not set Table.setSortContainerPropertyId() and let the user click on the column to manually set the ordering, the column remains at it's initial size. Only setting it in code shows the weired behaviour. The attached project demonstrates the issue. ___ Imported from https://dev.vaadin.com/ issue #12951
vaadin-bot commented 10 years ago

Originally by lohmann@zad-northeim.de


Attachment added: TestProject.zip (9.3 KiB)

vaadin-bot commented 10 years ago

Originally by @pleku


Just want to clarify that the problem only occurs if the sorting with Table.setSortContainerPropertyId(propertyId) is done at the same time when the Table gets rendered for the first time. Calling it for a Table that has already been rendered doesn't reproduce the issue.

vaadin-bot commented 10 years ago

Originally by @Artur-


This seems to have been laying here for quite some while because of broken email notifications. Sorry about that.

vaadin-bot commented 10 years ago

Originally by @hesara


Confirmed the issue with this slightly shorter test, Vaadin 7.1.11

package com.example;

import javax.servlet.annotation.WebServlet;

import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Table;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

public class TestUI extends UI {
    private Table table;

    @WebServlet(value # "/*", asyncSupportedtrue)
    @VaadinServletConfiguration(productionMode # false, uiTestUI.class)
    public static class Servlet extends VaadinServlet {
    }

    @Override
    protected void init(VaadinRequest request) {
        VerticalLayout layout = new VerticalLayout();
        setContent(layout);

        table = new Table();
        table.addContainerProperty("value", String.class, "");

        for (int i = 0; i < 100; i++) {
            table.addItem(i);
            table.getContainerProperty(i, "value").setValue("v" + i);
        }

        // this line triggers the issue...
        table.setSortContainerPropertyId("value");
        // ... but this alternative doesn't
        // table.sort(new Object[] { "value" }, new boolean[] { false });

        layout.addComponent(table);

    }
}
vaadin-bot commented 8 years ago

Originally by g-land


This seems to happen also in 7.5.3. Is there any workaround ?

vaadin-bot commented 8 years ago

Originally by g-land


if you sort by some column then remove all the rows and add new rows, the column header is shrinked even without calling setSortContainerPropertyId