Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update columns headers on attach #44

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ enhanced-grid-flow-demo/frontend/index.html
enhanced-grid-flow-demo/tsconfig.json
enhanced-grid-flow-demo/types.d.ts
enhanced-grid-flow-demo/vite.config.ts
enhanced-grid-flow-demo/src/main/bundles
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.vaadin.componentfactory.enhancedgrid;

import com.vaadin.componentfactory.enhancedgrid.bean.Person;
import com.vaadin.componentfactory.enhancedgrid.filtering.TextFilterField;
import com.vaadin.componentfactory.enhancedgrid.service.PersonService;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Paragraph;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.router.Route;
import java.util.List;

/**
* Opening grid in a dialog.
*/
@Route(value = "in-dialog", layout = MainLayout.class)
public class GridInDialogView extends Div {

public GridInDialogView() {
add(new Paragraph("Opening grid in a dialog"));

EnhancedGrid<Person> grid = new EnhancedGrid<>();
grid.setItems(getItems());
grid.addColumn(Person::getFirstName).setHeader("First Name", new TextFilterField());
grid.addColumn(Person::getLastName).setHeader("Last Name").setSortable(true);
grid.setFilterIcon(VaadinIcon.FILTER.create());

Dialog dialog = new Dialog();
dialog.add(grid);
dialog.setWidth("800px");
dialog.setWidth("600px");

Button button = new Button("Open dialog to see grid", e -> dialog.open());
add(button);
}

private List<Person> getItems() {
PersonService personService = new PersonService();
return personService.fetchAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ public MainLayout() {
final RouterLink multiTree = new RouterLink("Multiple Selection Tree Grid", MultiTreeGridView.class);
final RouterLink lazySingleTree = new RouterLink("Lazy Single Selection Tree Grid", LazySingleTreeGridView.class);
final RouterLink lazyMultiTree = new RouterLink("Lazy Multiple Selection Tree Grid", LazyMultiTreeGridView.class);
final RouterLink customFilterIcon = new RouterLink("Custom filter icon grid", CustomFilterIconView.class);
final RouterLink customFilterIcon = new RouterLink("Custom filter icon grid", CustomFilterIconView.class);
final RouterLink gridInDialog = new RouterLink("Open Grid in Dialog", GridInDialogView.class);

final VerticalLayout menuLayout = new VerticalLayout(simpleSingleGrid, simpleMultiGrid, lazySingleGrid, lazyMultiGrid,
singleTree, multiTree, lazySingleTree, lazyMultiTree, customFilterIcon);
singleTree, multiTree, lazySingleTree, lazyMultiTree, customFilterIcon, gridInDialog);
addToDrawer(menuLayout);
addToNavbar(drawerToggle);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import java.util.Comparator;
import java.util.Optional;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasValueAndElement;
import com.vaadin.flow.component.dependency.JsModule;
Expand Down Expand Up @@ -91,14 +90,19 @@ public EnhancedColumn<T> setHeader(Component headerComponent, HasValueAndElement
}

/** @see Column#setHeader(Component) */
@Override
public EnhancedColumn<T> setHeader(Component headerComponent) {
if (this.isFilterable()) {
this.grid.getElement().executeJs("monkeyPatchHeaderRenderer(this.$connector, $0)", getInternalId());
}
return (EnhancedColumn<T>) super.setHeader(headerComponent);
}
@Override
public EnhancedColumn<T> setHeader(Component headerComponent) {
this.renderHeader();
return (EnhancedColumn<T>) super.setHeader(headerComponent);
}

protected void renderHeader() {
if (this.isFilterable()) {
this.grid.getElement().executeJs("monkeyPatchHeaderRenderer(this.$connector, $0)",
getInternalId());
}
}

/**
* @see Column#setHeader(String)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,11 @@ private void updateFilterIcon() {
@Override
protected void onAttach(AttachEvent attachEvent) {
super.onAttach(attachEvent);
for(Column<T> column : getColumns()) {
EnhancedColumn<T> enhancedColumn = (EnhancedColumn<T>)column;
enhancedColumn.renderHeader();
enhancedColumn.updateFilterButtonStyle();
}
this.updateFilterIcon();
}
}
Expand Down
Loading