@@ -256,7 +256,7 @@ function cellClassGetter(col, isSelected, dataChangeStore, rowKeyGetter){
256256 } ;
257257}
258258
259- function initialiseColumns ( columns , rows , totalRowCount , columnWidthBy , maxColumnDataDisplayLength , qtPanelId ) {
259+ function initialiseColumns ( columns , rows , totalRowCount , columnWidthBy , maxColumnDataDisplayLength ) {
260260 let retColumns = [
261261 ...columns ,
262262 ] ;
@@ -265,7 +265,7 @@ function initialiseColumns(columns, rows, totalRowCount, columnWidthBy, maxColum
265265 canvasContext . font = '12px Roboto' ;
266266
267267 for ( const col of retColumns ) {
268- col . width = getColumnWidth ( col , rows , canvasContext , columnWidthBy , maxColumnDataDisplayLength , qtPanelId ) ;
268+ col . width = getColumnWidth ( col , rows , canvasContext , columnWidthBy , maxColumnDataDisplayLength ) ;
269269 col . resizable = true ;
270270 col . editorOptions = {
271271 commitOnOutsideClick : false ,
@@ -336,15 +336,8 @@ function formatColumns(columns, dataChangeStore, selectedColumns, onColumnSelect
336336
337337 return retColumns ;
338338}
339- // Helper to get or initialize the widths store on window
340- function getWidthsStore ( ) {
341- if ( ! window . pgAdminGridColumnWidths ) {
342- window . pgAdminGridColumnWidths = { } ;
343- }
344- return window . pgAdminGridColumnWidths ;
345- }
346339
347- function getColumnWidth ( column , rows , canvasContext , columnWidthBy , maxColumnDataDisplayLength , qtPanelId ) {
340+ function getColumnWidth ( column , rows , canvasContext , columnWidthBy , maxColumnDataDisplayLength ) {
348341 const dataWidthReducer = ( longest , nextRow ) => {
349342 let value = nextRow [ column . key ] ;
350343 if ( _ . isNull ( value ) || _ . isUndefined ( value ) ) {
@@ -377,19 +370,15 @@ function getColumnWidth(column, rows, canvasContext, columnWidthBy, maxColumnDat
377370 }
378371 }
379372
380- // Use window object for storing widths
381- const widthsStore = getWidthsStore ( ) ;
382- const savedWidths = widthsStore [ qtPanelId ] || { } ;
383-
384- return savedWidths [ column . display_name ] || width ;
373+ if ( ! window . columnWidths ) window . columnWidths = { } ;
374+ return window . columnWidths [ column . display_name ] || width ;
385375}
386376
387377export default function QueryToolDataGrid ( { columns, rows, totalRowCount, dataChangeStore,
388378 onSelectedCellChange, selectedColumns, onSelectedColumnsChange, columnWidthBy, startRowNum, maxColumnDataDisplayLength, ...props } ) {
389379 const [ readyColumns , setReadyColumns ] = useState ( [ ] ) ;
390380 const [ lastSelectedColumn , setLastSelectedColumn ] = useState ( null ) ;
391381 const eventBus = useContext ( QueryToolEventsContext ) ;
392- const qtPanelId = props . qtPanelId ;
393382 const onColumnSelected = ( columnIdx , isSelected , isShiftClick ) => {
394383 const newSelectedCols = new Set ( selectedColumns ) ;
395384 const start = isShiftClick && lastSelectedColumn ? Math . min ( columnIdx , lastSelectedColumn ) : columnIdx ;
@@ -445,15 +434,12 @@ export default function QueryToolDataGrid({columns, rows, totalRowCount, dataCha
445434
446435 // Save column width to window object on resize
447436 const handleColumnResize = ( column , width ) => {
448- const widthsStore = getWidthsStore ( ) ;
449- if ( ! widthsStore [ qtPanelId ] ) {
450- widthsStore [ qtPanelId ] = { } ;
451- }
452- widthsStore [ qtPanelId ] [ column . display_name ] = width ;
437+ if ( ! window . columnWidths ) window . columnWidths = { } ;
438+ window . columnWidths [ column . display_name ] = width ;
453439 } ;
454440
455441 useEffect ( ( ) => {
456- let initCols = initialiseColumns ( columns , rows , totalRowCount , columnWidthBy , maxColumnDataDisplayLength , qtPanelId ) ;
442+ let initCols = initialiseColumns ( columns , rows , totalRowCount , columnWidthBy , maxColumnDataDisplayLength ) ;
457443 setReadyColumns ( formatColumns ( initCols , dataChangeStore , selectedColumns , onColumnSelected , onSelectedColumnsChangeWrapped , props . rowKeyGetter ) ) ;
458444 } , [ columns ] ) ;
459445
@@ -475,7 +461,7 @@ export default function QueryToolDataGrid({columns, rows, totalRowCount, dataCha
475461 enableCellSelect = { true }
476462 onCopy = { handleCopy }
477463 onMultiCopy = { handleCopy }
478- onColumnResize = { handleColumnResize } // <-- Add this line
464+ onColumnResize = { handleColumnResize }
479465 renderers = { {
480466 renderRow : renderCustomRow ,
481467 } }
@@ -520,5 +506,4 @@ QueryToolDataGrid.propTypes = {
520506 columnWidthBy : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . number ] ) ,
521507 startRowNum : PropTypes . number ,
522508 maxColumnDataDisplayLength : PropTypes . number ,
523- qtPanelId : PropTypes . string ,
524509} ;
0 commit comments