@@ -256,7 +256,7 @@ function cellClassGetter(col, isSelected, dataChangeStore, rowKeyGetter){
256256 } ;
257257}
258258
259- function initialiseColumns ( columns , rows , totalRowCount , columnWidthBy , maxColumnDataDisplayLength ) {
259+ function initialiseColumns ( columns , rows , totalRowCount , columnWidthBy , maxColumnDataDisplayLength , qtPanelId ) {
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 ) ;
268+ col . width = getColumnWidth ( col , rows , canvasContext , columnWidthBy , maxColumnDataDisplayLength , qtPanelId ) ;
269269 col . resizable = true ;
270270 col . editorOptions = {
271271 commitOnOutsideClick : false ,
@@ -336,8 +336,15 @@ 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+ }
339346
340- function getColumnWidth ( column , rows , canvasContext , columnWidthBy , maxColumnDataDisplayLength ) {
347+ function getColumnWidth ( column , rows , canvasContext , columnWidthBy , maxColumnDataDisplayLength , qtPanelId ) {
341348 const dataWidthReducer = ( longest , nextRow ) => {
342349 let value = nextRow [ column . key ] ;
343350 if ( _ . isNull ( value ) || _ . isUndefined ( value ) ) {
@@ -369,14 +376,20 @@ function getColumnWidth(column, rows, canvasContext, columnWidthBy, maxColumnDat
369376 width = columnHeaderLen ;
370377 }
371378 }
372- return width ;
379+
380+ // Use window object for storing widths
381+ const widthsStore = getWidthsStore ( ) ;
382+ const savedWidths = widthsStore [ qtPanelId ] || { } ;
383+
384+ return savedWidths [ column . display_name ] || width ;
373385}
374386
375387export default function QueryToolDataGrid ( { columns, rows, totalRowCount, dataChangeStore,
376388 onSelectedCellChange, selectedColumns, onSelectedColumnsChange, columnWidthBy, startRowNum, maxColumnDataDisplayLength, ...props } ) {
377389 const [ readyColumns , setReadyColumns ] = useState ( [ ] ) ;
378390 const [ lastSelectedColumn , setLastSelectedColumn ] = useState ( null ) ;
379391 const eventBus = useContext ( QueryToolEventsContext ) ;
392+ const qtPanelId = props . qtPanelId ;
380393 const onColumnSelected = ( columnIdx , isSelected , isShiftClick ) => {
381394 const newSelectedCols = new Set ( selectedColumns ) ;
382395 const start = isShiftClick && lastSelectedColumn ? Math . min ( columnIdx , lastSelectedColumn ) : columnIdx ;
@@ -430,8 +443,17 @@ export default function QueryToolDataGrid({columns, rows, totalRowCount, dataCha
430443 onSelectedCellChange, handleShortcuts, startRowNum
431444 } ) , [ onSelectedCellChange ] ) ;
432445
446+ // Save column width to window object on resize
447+ const handleColumnResize = ( column , width ) => {
448+ const widthsStore = getWidthsStore ( ) ;
449+ if ( ! widthsStore [ qtPanelId ] ) {
450+ widthsStore [ qtPanelId ] = { } ;
451+ }
452+ widthsStore [ qtPanelId ] [ column . display_name ] = width ;
453+ } ;
454+
433455 useEffect ( ( ) => {
434- let initCols = initialiseColumns ( columns , rows , totalRowCount , columnWidthBy , maxColumnDataDisplayLength ) ;
456+ let initCols = initialiseColumns ( columns , rows , totalRowCount , columnWidthBy , maxColumnDataDisplayLength , qtPanelId ) ;
435457 setReadyColumns ( formatColumns ( initCols , dataChangeStore , selectedColumns , onColumnSelected , onSelectedColumnsChangeWrapped , props . rowKeyGetter ) ) ;
436458 } , [ columns ] ) ;
437459
@@ -453,6 +475,7 @@ export default function QueryToolDataGrid({columns, rows, totalRowCount, dataCha
453475 enableCellSelect = { true }
454476 onCopy = { handleCopy }
455477 onMultiCopy = { handleCopy }
478+ onColumnResize = { handleColumnResize } // <-- Add this line
456479 renderers = { {
457480 renderRow : renderCustomRow ,
458481 } }
@@ -497,4 +520,5 @@ QueryToolDataGrid.propTypes = {
497520 columnWidthBy : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . number ] ) ,
498521 startRowNum : PropTypes . number ,
499522 maxColumnDataDisplayLength : PropTypes . number ,
523+ qtPanelId : PropTypes . string ,
500524} ;
0 commit comments