vaadin / vaadin/framework

Grid.appendHeaderRow() collapsed in inner grid

Open
#7,546 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Stale v7
Dominant language
Java
Stars
1.8k
Forks
717
Avg merge
2d 6h
Merged PRs (30d)
3

Description

Originally by kodqaai


I created a grid (with a column name row and a filter row) inside an outer grid as genereted detail. If the inner grid is opened, the second (filter) row is empty and the originally second row's content is on/overrides the first row's content, because both 2 rows start at the same position (4. and 5. rows in the linked image)

[[Image(http://i68.tinypic.com/2en9hkp.jpg)]]
Outer grid is in 1-3 rows , inner grid is in 4-6 rows.

I could reproduce the bug in:
java : 1.8.0_40
vaadin : 7.6.3 and 7.5.5.
Spring boot : 1.3.3
os : "windows 10 pro -1511"
chrome : 48.0.2564.116 m
ie : 11.103.10586.0
firefox : 44.0.2

Instructions to reproduce the problem:

  1. Create a new spring boot project
  2. Insert this snippet to pom:
		<dependency>
			<groupId>com.vaadin</groupId>
			<artifactId>vaadin-spring-boot-starter</artifactId>
			<version>1.0.0</version>
		</dependency>
...
         <dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>com.vaadin</groupId>
				<artifactId>vaadin-bom</artifactId>
<!-- 				<version>7.5.5</version> -->
				<version>7.6.3</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>
  1. Insert the code below to the appropriate package
  2. Start the application and click(double) on the grid's row.
package com.example.grid.demo;

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

import com.vaadin.annotations.Theme;
import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.data.util.filter.SimpleStringFilter;
import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.ui.grid.HeightMode;
import com.vaadin.spring.annotation.SpringUI;
import com.vaadin.ui.Component;
import com.vaadin.ui.Field;
import com.vaadin.ui.Grid;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;

@SpringUI
@Theme("valo")
public class MainUI extends UI {
    @Override
    protected void init(VaadinRequest vaadinRequest) {
    	ArrayList<SimpleEntity> list = new ArrayList<SimpleEntity>();
    	list.add(new SimpleEntity("First", "Born"));
        setContent( new CommonGrid(list, true));
        
    }
    
    public class CommonGrid extends Grid {

    	boolean outerGrid = true;
    	
    	public CommonGrid(List<SimpleEntity> entities, boolean possibleDetails) {
    		this.outerGrid = possibleDetails;
    		setImmediate(true);
        	setHeightMode(HeightMode.CSS);
        	setSelectionMode(SelectionMode.SINGLE);
        	setResponsive(true);
        	
        	if (possibleDetails) {
        		addItemClickListener(itemClickEvent -> {
        			if (itemClickEvent.isDoubleClick()) {
        				Object itemId = itemClickEvent.getItemId();
        				
        				boolean visible = !isDetailsVisible(itemId);
        				setDetailsVisible(itemId, visible);
        			}
        		});
        		setDetailsGenerator(new DetailsGenerator() {
        			private static final long serialVersionUID = 1L;
        			
        			@Override
        			public Component getDetails(RowReference rowReference) {
        				return new CommonGrid(entities, false);
        			}
        		});
        	}
        	
        	showData(entities);
    	}
    	
    	public void showData(List<SimpleEntity> entities) {
			final BeanItemContainer<SimpleEntity> container = new BeanItemContainer<SimpleEntity>(SimpleEntity.class);
			container.addAll(entities);
			setContainerDataSource(container);
			
			appendFilterRow(container);
		}
	    
		public void collapseAllAndClearFilter(Grid grid) {
			HeaderRow filterRow = grid.getHeaderRow(0);
			BeanItemContainer<SimpleEntity> container = ((BeanItemContainer<SimpleEntity>)grid.getContainerDataSource());
			for (Object pid : container.getContainerPropertyIds()) {
				HeaderCell cell = filterRow.getCell(pid);
				if (cell != null) {
					Component component = cell.getComponent();
					if (component instanceof Field) {
						((Field)component).setValue(null);
						container.removeContainerFilters(pid);
					}
				}
			}
	
			grid.getContainerDataSource().getItemIds().forEach(item -> grid.setDetailsVisible(item, false));
		}
	
		public void appendFilterRow(final BeanItemContainer<SimpleEntity> container) {
			//Column names are not visible, when column names are omitted in the outer grid.
			//final HeaderRow filterRow = possibleDetails ? getHeaderRow(0) :appendHeaderRow();
			final HeaderRow filterRow = appendHeaderRow();
	
			for (final Object pid : getContainerDataSource().getContainerPropertyIds()) {
				final HeaderCell cell = filterRow.getCell(pid);
				if (cell == null) {
					continue;
				}
				final TextField filterField = new TextField();
				filterField.setInputPrompt(""+pid);
				filterField.setNullRepresentation("");
				filterField.addTextChangeListener(change -> {
					container.removeContainerFilters(pid);
					if (!change.getText().isEmpty()) {
						container.addContainerFilter(new SimpleStringFilter(pid, change.getText(), true, false));
					}
				});
				cell.setComponent(filterField);
			}
    	}
    }
    
    public class SimpleEntity {

		private String firstName;
		private String lastName;

		public SimpleEntity(String firstName, String lastName) {
			this.firstName = firstName;
			this.lastName = lastName;
		}
		
		public String getFirstName() {
			return firstName;
		}
		public void setFirstName(String firstName) {
			this.firstName = firstName;
		}
		public String getLastName() {
			return lastName;
		}
		public void setLastName(String lastName) {
			this.lastName = lastName;
		}
	}
}


Imported from https://dev.vaadin.com/ issue #19659

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.

Research direction

Start with the provided Spring Boot reproduction and inspect Grid.appendHeaderRow() when a CommonGrid is rendered as the outer grid's detail component. Reproduce the nested-grid case with the filter row, then trace why both header rows receive the same position. Done means the inner grid displays its column-name and filter rows separately without the filter row being empty or overwritten.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.