Cannot reset column width of a grid

Open Beginner friendly
#6,811 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
java
Domain
frontend

Research direction

Start at the Column.setWidth(String) method described in the issue and compare its handling of non-null and null widths with Element.removeProperty("width"). Verify that resetting with null restores the default column width, and add or update a regression test if the surrounding component tests provide an appropriate location.

Written by the indexing model from the issue text.

Description

vaadin-grid
Description of the bug

If I set the width of a column, either programmatic or by user (resizable=true) and I want programmatically to reset the width to apply defaults by calling Column.setWidth(null), the column is shown with a very large width.
If I call Column.getElement().removeProperty("width") instead , the column's width is changes to its default (as width has never been set explicitly).
The problem seems to be, that Column.setWidth(String) sets the width property to null instead of removing the property.
Instead of

        public Column<T> setWidth(String width) {
            getElement().setProperty("width", width);
            return this;
        }

it should be

        public Column<T> setWidth(String width) {
            if ( width != null ) {
                getElement().setProperty("width", width);
            } else {
                getElement().removeProperty("width");
            }
            return this;
        }

Although the workaround is easy, I think it should be fixed.

Versions
  • Vaadin / Flow version: 24.5.2
  • Java version: 17
  • OS version: Windows
  • Browser version (if applicable): Chrome
  • Application Server (if applicable): Tomcat 10
  • IDE (if applicable): Eclipse
Dominant language
Java
Stars
129
Forks
78
Avg merge
17h 42m
Merged PRs (30d)
196

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vaadin/flow-components

All issues in vaadin/flow-components

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.