Skip to content

Commit

Permalink
fix: allow setting grid footer toolbar over an existing one
Browse files Browse the repository at this point in the history
Close #50
  • Loading branch information
flang authored and javier-godoy committed Jan 3, 2023
1 parent 8cf8607 commit d3b5490
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.flowingcode.vaadin.addons.gridhelpers;

import java.io.Serializable;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.grid.FooterRow;
import com.vaadin.flow.component.grid.FooterRow.FooterCell;
import com.vaadin.flow.component.grid.Grid;
import java.io.Serializable;
import lombok.RequiredArgsConstructor;

@SuppressWarnings("serial")
Expand All @@ -13,17 +13,22 @@ class FooterToolbarGridHelper implements Serializable {

private final GridHelper<?> helper;

private FooterCell footerCell;

public void setFooterToolbar(Component toolBar) {
Grid<?> grid = helper.getGrid();
if (grid.getFooterRows().isEmpty()) {
// create a fake footer and hide it (workaround: https://github.com/vaadin/flow-components/issues/1558#issuecomment-987783794)
// create a fake footer and hide it (workaround:
// https://github.com/vaadin/flow-components/issues/1558#issuecomment-987783794)
grid.appendFooterRow();
grid.getElement().getThemeList().add("hide-first-footer");
}
FooterRow fr = grid.appendFooterRow();
FooterCell fc = fr.join(grid.getColumns().toArray(new Grid.Column[0]));
toolBar.getElement().setAttribute("fcGh-footer",true);
fc.setComponent(toolBar);
if (footerCell == null) {
FooterRow fr = grid.appendFooterRow();
footerCell = fr.join(grid.getColumns().toArray(new Grid.Column[0]));
}
toolBar.getElement().setAttribute("fcGh-footer", true);
footerCell.setComponent(toolBar);
}

}

0 comments on commit d3b5490

Please sign in to comment.