@@ -17,6 +17,7 @@ import GetAppRoundedIcon from '@mui/icons-material/GetAppRounded';
1717import { PgIconButton } from '../../../../../../static/js/components/Buttons' ;
1818import { QUERY_TOOL_EVENTS } from '../QueryToolConstants' ;
1919import { QueryToolEventsContext } from '../QueryToolComponent' ;
20+ import { DataGridExtrasContext } from './index' ;
2021
2122const StyledNullAndDefaultFormatter = styled ( NullAndDefaultFormatter ) ( ( { theme} ) => ( {
2223 '& .Formatters-disabledCell' : {
@@ -73,16 +74,24 @@ export function NumberFormatter({row, column}) {
7374}
7475NumberFormatter . propTypes = FormatterPropTypes ;
7576
76- export function BinaryFormatter ( { row, column, ... props } ) {
77+ export function BinaryFormatter ( { row, column} ) {
7778 let value = row [ column . key ] ;
7879 const eventBus = useContext ( QueryToolEventsContext ) ;
80+ const dataGridExtras = useContext ( DataGridExtrasContext ) ;
7981 const downloadBinaryData = usePreferences ( ) . getPreferences ( 'misc' , 'enable_binary_data_download' ) . value ;
82+
83+ // Use clientPK as the absolute row position
84+ // rowKeyGetter returns the clientPK value which is a sequential counter (0, 1, 2, ...)
85+ // that persists across pagination and represents the 0-based absolute position in the result set
86+ const absoluteRowPos = parseInt ( dataGridExtras ?. rowKeyGetter ?. ( row ) ?? 0 ) ;
87+ console . log ( absoluteRowPos )
88+
8089 return (
8190 < StyledNullAndDefaultFormatter value = { value } column = { column } >
8291 < span className = 'Formatters-disabledCell' > [{ value } ]</ span >
83- { downloadBinaryData &&
92+ { downloadBinaryData &&
8493 < PgIconButton size = "xs" title = { gettext ( 'Download binary data' ) } icon = { < GetAppRoundedIcon /> }
85- onClick = { ( ) => eventBus . fireEvent ( QUERY_TOOL_EVENTS . TRIGGER_SAVE_BINARY_DATA , props . rowIdx , column . pos ) } /> }
94+ onClick = { ( ) => eventBus . fireEvent ( QUERY_TOOL_EVENTS . TRIGGER_SAVE_BINARY_DATA , absoluteRowPos , column . pos ) } /> }
8695 </ StyledNullAndDefaultFormatter >
8796 ) ;
8897}
0 commit comments