Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grid : Column header is not updated on client-side when column was invisible in between #5516

Closed
SonReimer opened this issue Sep 27, 2023 · 0 comments · Fixed by vaadin/web-components#6648
Assignees

Comments

@SonReimer
Copy link

Description

I have a grid with 2 columns.
I added a button

  • to toogle visibility of the second column and
  • set the header of the second column when I set it visible.

When toggling the visibility of the second column it's header is not updated.

Expected outcome

I would expect the column header to be updated

Minimal reproducible example

package org.vaadin.example;

import java.util.ArrayList;
import java.util.List;

import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.grid.Grid.Column;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.Route;

@Route
public class MainView extends VerticalLayout {

	public static class Person2 {
		private String name1;
		private String name2;

		public String getName1() {
			return name1;
		}
		public void setName1(String name1) {
			this.name1 = name1;
		}
		public String getName2() {
			return name2;
		}
		public void setName2(String name2) {
			this.name2 = name2;
		}

	}

    public MainView() {
        
        Grid<Person2> myGrid = new Grid<>();
        myGrid.addColumn(Person2::getName1).setKey("Name1").setHeader("Name1");
        myGrid.addColumn(Person2::getName2).setKey("Name2").setHeader("Name2");
        
        List<Person2> items = new ArrayList<>();
        Person2 person2 = new Person2();
        person2.setName1("Henry1");
        person2.setName2("Michael1");
        items.add(person2);
        person2 = new Person2();
        person2.setName1("Henry2");
        person2.setName2("Michael2");
        items.add(person2);        
        myGrid.setItems(items);
        
        Button myGridButton = new Button("show Name2", e -> {
        	Column<Person2> column = myGrid.getColumnByKey("Name2");
        	if (!column.isVisible()) {
            	column.setVisible(true);
	        	column.setHeader(column.getHeaderText() + " X");
	        	System.out.println("ColumnHeader: " + column.getHeaderText());
	        	items.forEach(item -> item.setName2(item.getName2() + " X"));
	        	myGrid.getListDataView().refreshAll();
        	} else {
            	column.setVisible(false);
        	}
        });
        

        add(myGridButton, myGrid/*grid, select, name, sayHello*/);

    }

}

Steps to reproduce

see above

Environment

Vaadin version(s): 23.3.24, 24.0.2
OS: Windows

Browsers

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants