Skip to content

Commit

Permalink
Merge pull request #36 from vaadin-component-factory/fix/preserve-on-…
Browse files Browse the repository at this point in the history
…refresh

fix: add the header component after a refresh event
  • Loading branch information
sujoykd authored Jan 12, 2024
2 parents d97690b + 378af86 commit e3ae6be
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,17 @@ package-lock.json
package.json
webpack.config.js
webpack.generated.js
vite.generated.ts

enhanced-grid-flow/src/main/resources/rebel.xml
.classpath
.project
.settings
.vscode/settings.json

enhanced-grid-flow-demo/frontend/generated
enhanced-grid-flow-demo/src/main/dev-bundle
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.data.renderer.NumberRenderer;
import com.vaadin.flow.router.PreserveOnRefresh;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.router.RouteAlias;

Expand All @@ -27,6 +28,7 @@
*/
@Route(value = "", layout = MainLayout.class)
@RouteAlias(value = "single-grid", layout = MainLayout.class)
@PreserveOnRefresh
public class SimpleSingleSelectView extends Div {

public SimpleSingleSelectView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
*/

import java.util.Comparator;

import org.apache.commons.lang3.StringUtils;
import java.util.Optional;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasValueAndElement;
Expand All @@ -38,7 +37,8 @@
import com.vaadin.flow.component.icon.Icon;
import com.vaadin.flow.data.renderer.Renderer;
import com.vaadin.flow.function.ValueProvider;
import com.vaadin.flow.internal.HtmlUtils;
import com.vaadin.flow.router.BeforeEnterEvent;
import com.vaadin.flow.router.BeforeEnterObserver;

/**
*
Expand All @@ -48,7 +48,7 @@
*/
@Uses(Icon.class)
@JsModule(value = "./src/enhanced-grid-sorter.js")
public class EnhancedColumn<T> extends Grid.Column<T> {
public class EnhancedColumn<T> extends Grid.Column<T> implements BeforeEnterObserver {

private HasValueAndElement<?, ? extends FilterFieldDto> filter;

Expand Down Expand Up @@ -285,4 +285,15 @@ protected void setFilterIcon(Icon icon) {
public EnhancedColumn<T> setKey(String key) {
return (EnhancedColumn<T>) super.setKey(key);
}

@Override
public void beforeEnter(BeforeEnterEvent beforeEnterEvent) {
if (beforeEnterEvent.isRefreshEvent()) {
Optional.ofNullable(this.getHeaderComponent())
.ifPresent(headerComponent -> {
this.setHeader(headerComponent);
this.updateFilterButtonStyle();
});
}
}
}

0 comments on commit e3ae6be

Please sign in to comment.