Skip to content

Commit

Permalink
Ensure Grid details rows get a full refresh when a column is sorted. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ansku committed Jul 21, 2021
1 parent 512703d commit 40e3557
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ public void dataUpdated(int firstRowIndex, int numberOfRows) {
boolean scrollToFirst = numberOfRows == 1
&& latestVisibleRowRange.contains(firstRowIndex);

if (!newVisibleRowRange.equals(latestVisibleRowRange)) {
if (!newVisibleRowRange.equals(latestVisibleRowRange)
|| updatedRange.equals(newVisibleRowRange)) {
// update visible range
latestVisibleRowRange = newVisibleRowRange;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.vaadin.tests.components.grid;

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

import com.vaadin.data.provider.ListDataProvider;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Label;

public class GridOpenDetailsSort extends AbstractTestUI {

@Override
protected void setup(VaadinRequest request) {
Grid<String> testGrid = new Grid<>();

testGrid.addColumn(item -> item).setCaption("column").setId("column");

List<String> list = new ArrayList<>();
list.add("row3");
list.add("row2");
list.add("row1");
ListDataProvider<String> dataProvider = new ListDataProvider<>(list);

testGrid.setDataProvider(dataProvider);
testGrid.setDetailsGenerator(item -> new Label("details - " + item));
list.forEach(item -> testGrid.setDetailsVisible(item, true));

addComponent(testGrid);
}

@Override
protected Integer getTicketNumber() {
return 12341;
}

@Override
protected String getTestDescription() {
return "Already open details rows shouldn't break when the Grid is sorted.";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.vaadin.tests.components.grid;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.List;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.vaadin.testbench.elements.GridElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

public class GridOpenDetailsSortTest extends MultiBrowserTest {

@Test
public void sort() {
openTestURL();
GridElement grid = $(GridElement.class).first();
assertRow(grid, 0, "row3");
assertDetails();

grid.getHeaderCell(0, 0).click();
assertTrue("First column should be sorted ascending",
grid.getHeaderCell(0, 0).getAttribute("class")
.contains("sort-asc"));
assertRow(grid, 0, "row1");
assertDetails();
}

private void assertRow(GridElement grid, int row, String value) {
assertEquals(String.valueOf(value), grid.getCell(row, 0).getText());
}

private void assertDetails() {
List<WebElement> details = findElements(By.className("v-grid-spacer"));
assertEquals("Unexpected amount of details,", 3, details.size());
for (WebElement detail : details) {
assertEquals("Unexpected detail contents,", 1,
detail.findElements(By.className("v-label")).size());
}
}
}

0 comments on commit 40e3557

Please sign in to comment.