@@ -51,6 +51,7 @@ import { formatCellEditorDateValue } from "../../table/CellRenderer/DateCellRend
5151import { AppContextType } from "../../../contexts/AppProvider" ;
5252import { ICellEditorDate } from "../date/UIEditorDate" ;
5353import useAppContext from "../../../hooks/app-hooks/useAppContext" ;
54+ import { VirtualScroller } from "primereact/virtualscroller" ;
5455
5556interface ReferencedColumnNames {
5657 columnNames : string [ ]
@@ -875,7 +876,7 @@ const UIEditorLinked: FC<IEditorLinked & IExtendableLinkedEditor & IComponentCon
875876
876877 // Handles the lazy-load, if the linked is at the end but not every row is fetched, it fetches 100 new rows
877878 const handleLazyLoad = ( event :any ) => {
878- if ( event . last >= providedData . length && ! props . context . contentStore . getDataBook ( props . screenName , props . cellEditor . linkReference . referencedDataBook || "" ) ?. isAllFetched ) {
879+ if ( event . last >= providedData . length && ! props . context . contentStore . getDataBook ( props . screenName , props . cellEditor . linkReference . referencedDataBook || "" ) ?. isAllFetched ) {
879880 const fetchReq = createFetchRequest ( ) ;
880881 fetchReq . dataProvider = props . cellEditor . linkReference . referencedDataBook ;
881882 fetchReq . fromRow = providedData . length ;
@@ -1112,7 +1113,6 @@ const UIEditorLinked: FC<IEditorLinked & IExtendableLinkedEditor & IComponentCon
11121113 }
11131114 } }
11141115 onShow = { ( ) => {
1115- //select currently selected suggestion
11161116 if ( suggestions . length && linkedRef . current ?. getOverlay ( ) && props . columnName ) {
11171117 const { linkReference } = props . cellEditor ;
11181118 const grouped = suggestions . length == 1 && suggestions [ 0 ] . items ?. length ;
@@ -1121,10 +1121,17 @@ const UIEditorLinked: FC<IEditorLinked & IExtendableLinkedEditor & IComponentCon
11211121 ( s :any ) => s [ linkReference . referencedColumnNames [ linkReference . columnNames . indexOf ( props . columnName ) ] ] == props . selectedRow ?. data [ props . columnName ]
11221122 ) ;
11231123 if ( index >= 0 ) {
1124- const el = linkedRef . current ?. getOverlay ( ) . querySelectorAll ( '.p-autocomplete-item' ) [ index ] ;
1125- el . classList . add ( 'p-highlight' ) ;
1126- el . setAttribute ( 'data-p-highlight' , 'true' ) ;
1127- el . scrollIntoView ( { behavior : "instant" as ScrollBehavior } ) ;
1124+ // Virtual scroller does not scroll, if index is smaller than last - 2
1125+ // We want to show 2 items above the selected item, that the selected item is not the top one.
1126+ const last = linkedRef . current ?. getVirtualScroller ( ) . getRenderedRange ( ) . viewport . last ;
1127+ const scrollpos = index < last ? 0 : index - 2 ;
1128+ linkedRef . current ?. getVirtualScroller ( ) . scrollToIndex ( scrollpos , "auto" ) ;
1129+
1130+ setTimeout ( ( ) => {
1131+ const el = linkedRef . current ?. getOverlay ( ) . querySelectorAll ( '.p-autocomplete-item' ) [ index - linkedRef . current ?. getVirtualScroller ( ) . getRenderedRange ( ) . first ] ;
1132+ el ?. classList . add ( 'p-highlight' ) ;
1133+ el ?. setAttribute ( 'data-p-highlight' , 'true' ) ;
1134+ } , 50 ) ;
11281135 }
11291136 }
11301137 } }
0 commit comments