Skip to content

Commit

Permalink
check and add header components in column when entering from refresh …
Browse files Browse the repository at this point in the history
…event
  • Loading branch information
sujoykd committed Jan 11, 2024
1 parent d97690b commit e3a80b8
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ 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
23 changes: 23 additions & 0 deletions enhanced-grid-flow-demo/frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<!--
This file is auto-generated by Vaadin.
-->

<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
body, #outlet {
height: 100vh;
width: 100%;
margin: 0;
}
</style>
<!-- index.ts is included here automatically (either by the dev server or during the build) -->
</head>
<body>
<!-- This outlet div is where the views are rendered -->
<div id="outlet"></div>
</body>
</html>
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
39 changes: 39 additions & 0 deletions enhanced-grid-flow-demo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// This TypeScript configuration file is generated by vaadin-maven-plugin.
// This is needed for TypeScript compiler to compile your TypeScript code in the project.
// It is recommended to commit this file to the VCS.
// You might want to change the configurations to fit your preferences
// For more information about the configurations, please refer to http://www.typescriptlang.org/docs/handbook/tsconfig-json.html
{
"flow_version": "23.3.4",
"compilerOptions": {
"sourceMap": true,
"jsx": "react-jsx",
"inlineSources": true,
"module": "esNext",
"target": "es2020",
"moduleResolution": "node",
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noImplicitAny": true,
"noImplicitThis": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"experimentalDecorators": true,
"useDefineForClassFields": false,
"baseUrl": "frontend",
"paths": {
"@vaadin/flow-frontend": ["generated/jar-resources"],
"@vaadin/flow-frontend/*": ["generated/jar-resources/*"],
"Frontend/*": ["*"]
}
},
"include": [
"frontend/**/*",
"types.d.ts"
],
"exclude": [
"frontend/generated/jar-resources/**"
]
}
10 changes: 10 additions & 0 deletions enhanced-grid-flow-demo/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This TypeScript modules definition file is generated by vaadin-maven-plugin.
// You can not directly import your different static files into TypeScript,
// This is needed for TypeScript compiler to declare and export as a TypeScript module.
// It is recommended to commit this file to the VCS.
// You might want to change the configurations to fit your preferences
declare module '*.css' {
import { CSSResultGroup } from 'lit';
const content: CSSResultGroup;
export default content;
}
9 changes: 9 additions & 0 deletions enhanced-grid-flow-demo/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { UserConfigFn } from 'vite';
import { overrideVaadinConfig } from './vite.generated';

const customConfig: UserConfigFn = (env) => ({
// Here you can add custom Vite parameters
// https://vitejs.dev/config/
});

export default overrideVaadinConfig(customConfig);
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 e3a80b8

Please sign in to comment.