From 6838b111b42cb1db2fa5c20570d15fa6a6d0f6a4 Mon Sep 17 00:00:00 2001 From: Patrik Hellgren Date: Tue, 27 Feb 2024 23:13:44 +0100 Subject: [PATCH 1/3] Add feature sticky header --- .../src/components/DetailsListComponent.tsx | 50 +++++++++++++++++-- .../results/detailsList/DetailListLayout.ts | 37 +++++++++++++- .../results/detailsList/details-list.html | 17 +++++++ search-parts/src/loc/commonStrings.d.ts | 2 + search-parts/src/loc/da-dk.js | 4 +- search-parts/src/loc/de-de.js | 4 +- search-parts/src/loc/en-us.js | 4 +- search-parts/src/loc/es-es.js | 4 +- search-parts/src/loc/fi-fi.js | 4 +- search-parts/src/loc/fr-fr.js | 4 +- search-parts/src/loc/nb-no.js | 4 +- search-parts/src/loc/nl-nl.js | 4 +- search-parts/src/loc/pl-pl.js | 4 +- search-parts/src/loc/pt-br.js | 4 +- search-parts/src/loc/sv-SE.js | 4 +- 15 files changed, 134 insertions(+), 16 deletions(-) diff --git a/search-parts/src/components/DetailsListComponent.tsx b/search-parts/src/components/DetailsListComponent.tsx index 0dec8285..d021b469 100644 --- a/search-parts/src/components/DetailsListComponent.tsx +++ b/search-parts/src/components/DetailsListComponent.tsx @@ -210,6 +210,16 @@ export interface IDetailsListComponentProps { * The template service instance */ templateService: ITemplateService; + + /** + * If the header should be sticky + */ + enableStickyHeader?: boolean; + + /** + * The height of the list view when sticky header is enabled + */ + stickyHeaderListViewHeight?: number; } export interface IDetailsListComponentState { @@ -226,6 +236,16 @@ export class DetailsListComponent extends React.Component - + + + + + + + + ); + } + + return ( + + + ); } @@ -551,7 +585,7 @@ export class DetailsListComponent extends React.Component; } - private _onRenderDetailsHeader(props: IDetailsHeaderProps): JSX.Element { + private _onRenderDetailsHeader(props: IDetailsHeaderProps, defaultRender): JSX.Element { props.onRenderColumnHeaderTooltip = (tooltipHostProps: ITooltipHostProps) => { @@ -578,7 +612,15 @@ export class DetailsListComponent extends React.Component; }; - return ; + if (this.props.enableStickyHeader) { + return ( + + {defaultRender!({...props, theme: this.props.themeVariant as ITheme})} + + ); + } + + return defaultRender!({...props, theme: this.props.themeVariant as ITheme}); } private _onColumnClick = (ev: React.MouseEvent, column: IColumn): void => { diff --git a/search-parts/src/layouts/results/detailsList/DetailListLayout.ts b/search-parts/src/layouts/results/detailsList/DetailListLayout.ts index 266e877c..cdabe9f6 100644 --- a/search-parts/src/layouts/results/detailsList/DetailListLayout.ts +++ b/search-parts/src/layouts/results/detailsList/DetailListLayout.ts @@ -7,6 +7,7 @@ import { IPropertyPaneField, PropertyPaneToggle, PropertyPaneDropdown, PropertyP import { TemplateValueFieldEditor, ITemplateValueFieldEditorProps } from '../../../controls/TemplateValueFieldEditor/TemplateValueFieldEditor'; import { AsyncCombo } from "../../../controls/PropertyPaneAsyncCombo/components/AsyncCombo"; import { IAsyncComboProps } from "../../../controls/PropertyPaneAsyncCombo/components/IAsyncComboProps"; +import { PropertyFieldNumber } from "@pnp/spfx-property-controls"; /** * Details List Builtin Layout @@ -47,6 +48,16 @@ export interface IDetailsListLayoutProperties { * If groups should collapsed by default */ groupsCollapsed: boolean; + + /** + * If the header should be sticky + */ + enableStickyHeader: boolean; + + /** + * The height of the list view when sticky header is enabled + */ + stickyHeaderListViewHeight: number; } export class DetailsListLayout extends BaseLayout { @@ -303,6 +314,26 @@ export class DetailsListLayout extends BaseLayout ); } + propertyPaneFields.push( + PropertyPaneToggle('layoutProperties.enableStickyHeader', { + label: strings.Layouts.DetailsList.EnableStickyHeader || 'Enable Sticky Header', + checked: this.properties.enableStickyHeader + })); + + //Sticky header options + if (this.properties.enableStickyHeader) { + propertyPaneFields.push( + PropertyFieldNumber('layoutProperties.stickyHeaderListViewHeight', { + label: strings.Layouts.DetailsList.StickyHeaderListViewHeight, + maxValue: 5000, + minValue: 200, + value: this.properties.stickyHeaderListViewHeight ? this.properties.stickyHeaderListViewHeight : 500, + disabled: !this.properties.enableStickyHeader, + key: 'layoutProperties.stickyHeaderListViewHeight', + }) + ); + } + return propertyPaneFields; } @@ -311,5 +342,9 @@ export class DetailsListLayout extends BaseLayout if (propertyPath.localeCompare('layoutProperties.enableGrouping') === 0) { this.properties.groupByField = ''; } - } + + if (propertyPath.localeCompare('layoutProperties.enableStickyHeader') === 0) { + this.properties.stickyHeaderListViewHeight = 500; + } + } } diff --git a/search-parts/src/layouts/results/detailsList/details-list.html b/search-parts/src/layouts/results/detailsList/details-list.html index 8014c944..6d918064 100644 --- a/search-parts/src/layouts/results/detailsList/details-list.html +++ b/search-parts/src/layouts/results/detailsList/details-list.html @@ -1,6 +1,21 @@