Skip to content

setColumnOrder not working if not called before #9119

@mukherjeesudebi

Description

@mukherjeesudebi

Description

setColumnOrder not working if done inside a button click.

It works only if it has been called before.

It works in 24.9.13 but not in 25.1.1

Expected outcome

It should work irrespective of whether setColumnOrder has been worked before or not

Minimal reproducible example

record Element(String name) {

}

@Route("grid-col-order")
class GridColumnOrder extends VerticalLayout {

	final Grid<Element> taskGrid;

	GridColumnOrder() {
		taskGrid = new Grid<>();
		var list = new ArrayList<Element>();

		list.add(new Element("Foo"));
		list.add(new Element("Bar"));

		var listProvider = new ListDataProvider<>(list);
		taskGrid.setDataProvider(listProvider);

		var firstColumn = taskGrid.addColumn(Element::name).setHeader("First Column");
		var secondColumn = taskGrid.addColumn(element -> "Second Column").setHeader("Second");
		var thirdColumn = taskGrid.addColumn(element -> "Third Column").setHeader("Third");
		
		//Uncomment the below code to check the difference in behaviour
		//var columnList1 = new ArrayList<Grid.Column<Element>>();
		//columnList1.add(secondColumn);
		//columnList1.add(firstColumn);		
		//columnList1.add(thirdColumn);
		//taskGrid.setColumnOrder(columnList1);
		
		taskGrid.setColumnReorderingAllowed(true);

		var resetButton = new Button("Reset Order");
		resetButton.addClickListener(event -> {
			var columnList = new ArrayList<Grid.Column<Element>>();
			columnList.add(firstColumn);
			columnList.add(secondColumn);
			columnList.add(thirdColumn);
			taskGrid.setColumnOrder(columnList);
		});
		add(resetButton);

		setSizeFull();
		add(taskGrid);
	}
}

Steps to reproduce

  1. Add the code to a 25.1.1 sample
  2. Change the column order
  3. Click the button to check the reorder does not happen
  4. Uncomment the commented lines
  5. Change the column order
  6. Click the button to check that the reorder happens

Environment

Vaadin version(s): 25.1.1

Browsers

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions