aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorArtur <artur@vaadin.com>2017-03-10 17:08:44 +0200
committerPekka Hyvönen <pekka@vaadin.com>2017-03-10 17:08:44 +0200
commit4e0b27d8222dbd32d3df3f9bd9cbe1bcfe407cd4 (patch)
tree9d1a8d84dcacec2a0d0375866b70ce9447f3d93f /server
parentdc657b3208f1eaf1b41b3640bd854cc0e2ef47f9 (diff)
downloadvaadin-framework-4e0b27d8222dbd32d3df3f9bd9cbe1bcfe407cd4.tar.gz
vaadin-framework-4e0b27d8222dbd32d3df3f9bd9cbe1bcfe407cd4.zip
Update frozen column count when a frozen column is removed (#8788)
* Update frozen column count when a frozen column is removed
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/com/vaadin/ui/Grid.java11
-rw-r--r--server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java36
2 files changed, 45 insertions, 2 deletions
diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java
index 818f18899b..3611726ecd 100644
--- a/server/src/main/java/com/vaadin/ui/Grid.java
+++ b/server/src/main/java/com/vaadin/ui/Grid.java
@@ -85,7 +85,6 @@ import com.vaadin.shared.ui.grid.GridConstants;
import com.vaadin.shared.ui.grid.GridConstants.Section;
import com.vaadin.shared.ui.grid.GridServerRpc;
import com.vaadin.shared.ui.grid.GridState;
-import com.vaadin.shared.ui.grid.GridStaticCellType;
import com.vaadin.shared.ui.grid.HeightMode;
import com.vaadin.shared.ui.grid.ScrollDestination;
import com.vaadin.shared.ui.grid.SectionState;
@@ -101,7 +100,6 @@ import com.vaadin.ui.components.grid.FooterRow;
import com.vaadin.ui.components.grid.GridSelectionModel;
import com.vaadin.ui.components.grid.Header;
import com.vaadin.ui.components.grid.Header.Row;
-import com.vaadin.ui.components.grid.HeaderCell;
import com.vaadin.ui.components.grid.HeaderRow;
import com.vaadin.ui.components.grid.ItemClickListener;
import com.vaadin.ui.components.grid.MultiSelectionModel;
@@ -2342,12 +2340,18 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents,
public void removeColumn(Column<T, ?> column) {
if (columnSet.remove(column)) {
String columnId = column.getInternalId();
+ int displayIndex = getState(false).columnOrder.indexOf(columnId);
+ assert displayIndex != -1 : "Tried to remove a column which is not included in columnOrder. This should not be possible as all columns should be in columnOrder.";
columnKeys.remove(columnId);
columnIds.remove(column.getId());
column.remove();
getHeader().removeColumn(columnId);
getFooter().removeColumn(columnId);
getState(true).columnOrder.remove(columnId);
+
+ if (displayIndex < getFrozenColumnCount()) {
+ setFrozenColumnCount(getFrozenColumnCount() - 1);
+ }
}
}
@@ -2473,6 +2477,9 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents,
* checkbox column will still be frozen if it's in use. Setting the count to
* -1 will also disable the selection column.
* <p>
+ * <em>NOTE:</em> this count includes {@link Column#isHidden() hidden
+ * columns} in the count.
+ * <p>
* The default value is 0.
*
* @param numberOfColumns
diff --git a/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java b/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java
index c85cf5ee73..8662aacffa 100644
--- a/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java
+++ b/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java
@@ -418,6 +418,42 @@ public class GridTest {
}
@Test
+ public void removeFrozenColumn() {
+ grid.setFrozenColumnCount(3);
+ grid.removeColumn(fooColumn);
+ assertEquals(2, grid.getFrozenColumnCount());
+ }
+
+ @Test
+ public void removeHiddenFrozenColumn() {
+ lengthColumn.setHidden(true);
+ grid.setFrozenColumnCount(3);
+ grid.removeColumn(lengthColumn);
+ assertEquals(2, grid.getFrozenColumnCount());
+ }
+
+ @Test
+ public void removeNonFrozenColumn() {
+ grid.setFrozenColumnCount(3);
+ grid.removeColumn(randomColumn);
+ assertEquals(3, grid.getFrozenColumnCount());
+ }
+
+ @Test
+ public void testFrozenColumnRemoveColumn() {
+ assertEquals("Grid should not start with a frozen column", 0,
+ grid.getFrozenColumnCount());
+
+ int columnCount = grid.getColumns().size();
+ grid.setFrozenColumnCount(columnCount);
+
+ grid.removeColumn(grid.getColumns().get(0));
+ assertEquals(
+ "Frozen column count should be updated when removing a frozen column",
+ columnCount - 1, grid.getFrozenColumnCount());
+ }
+
+ @Test
public void setColumns_reorder() {
// Will remove other columns
grid.setColumns("length", "foo");