diff --git a/src/Gridler/components/Computer.tsx b/src/Gridler/components/Computer.tsx index 7d9c567..c3fff7f 100644 --- a/src/Gridler/components/Computer.tsx +++ b/src/Gridler/components/Computer.tsx @@ -282,7 +282,6 @@ export const Computer = React.memo(() => { if (ready && selectFirstRowOnMount) { const scrollToRowKey = getState('scrollToRowKey'); - if (scrollToRowKey && scrollToRowKey >= 0) { return; } @@ -294,20 +293,18 @@ export const Computer = React.memo(() => { const firstRow = firstBuffer?.[keyField] ?? -1; const currentValues = getState('values') ?? []; - if ( - !(values && values.length > 0) && - firstRow && - firstRow > 0 && - (currentValues.length ?? 0) === 0 - ) { - const values = [firstBuffer, ...(currentValues as Array>)]; + if (!firstBuffer) { + return; + } + + if (firstRow && firstRow > 0 && (currentValues.length ?? 0) === 0) { + const newValues = [firstBuffer]; const onChange = getState('onChange'); - //console.log('Selecting first row:', firstRow, firstBuffer, values); if (onChange) { - onChange(values); + onChange(newValues); } else { - setState('values', values); + setState('values', newValues); } setState('scrollToRowKey', firstRow); @@ -320,7 +317,7 @@ export const Computer = React.memo(() => { return () => { _events?.removeEventListener('loadPage', loadPage); }; - }, [ready, selectFirstRowOnMount]); + }, [ready, selectFirstRowOnMount, values]); /// logic to apply the selected row. // useEffect(() => { @@ -353,8 +350,6 @@ export const Computer = React.memo(() => { //console.log('Computer:Scrolling to key:', key); getRowIndexByKey?.(key).then((r) => { if (r !== undefined) { - console.log('Scrolling to selected row:', r, selectedRowKey, scrollToRowKey); - if (selectedRowKey) { const onChange = getState('onChange'); const selected = [{ [getState('keyField') ?? 'id']: selectedRowKey }]; @@ -382,15 +377,6 @@ export const Computer = React.memo(() => { } }, [scrollToRowKey, selectedRowKey]); - // console.log('Gridler:Debug:Computer', { - // colFilters, - // colOrder, - // colSize, - // colSort, - // columns, - // uniqueid - // }); - return <>; });