@@ -14,7 +14,6 @@ import SearchIcon from '@mui/icons-material/Search';
1414import React , { useEffect , useState , useMemo } from 'react' ;
1515import { getConf } from '@jbrowse/core/configuration' ;
1616import { AppBar , Box , Button , Dialog , Paper , Popover , Toolbar , Tooltip , Typography } from '@mui/material' ;
17- import ArrowPagination from './ArrowPagination' ;
1817import { FilterFormModal } from './FilterFormModal' ;
1918import { getAdapter } from '@jbrowse/core/data_adapters/dataAdapterCache' ;
2019import { NoAssemblyRegion } from '@jbrowse/core/util/types' ;
@@ -41,8 +40,6 @@ const VariantTableWidget = observer(props => {
4140 const { assemblyNames, assemblyManager } = session
4241 const { view } = session
4342
44- const currentOffset = parseInt ( new URLSearchParams ( window . location . search ) . get ( 'offset' ) || '0' ) ;
45-
4643 // The code expects a proper GUID, yet the trackId is a string containing the GUID + filename
4744 const trackGUID = truncateToValidGUID ( props . trackId )
4845
@@ -61,25 +58,30 @@ const VariantTableWidget = observer(props => {
6158
6259 return obj
6360 } ) )
61+ setTotalHits ( data . totalHits )
6462 setDataLoaded ( true )
6563 }
6664
6765 function handleModalClose ( widget ) {
6866 session . hideWidget ( widget )
6967 }
7068
71- function handleQuery ( passedFilters , pushToHistory ) {
69+ function handleQuery ( passedFilters , pushToHistory , pageQueryModel = pageSizeModel ) {
70+ const { page = pageSizeModel . page , pageSize = pageSizeModel . pageSize } = pageQueryModel ;
71+
7272 const encodedSearchString = createEncodedFilterString ( passedFilters , false ) ;
7373 const currentUrl = new URL ( window . location . href ) ;
7474 currentUrl . searchParams . set ( "searchString" , encodedSearchString ) ;
75+ currentUrl . searchParams . set ( "page" , page . toString ( ) ) ;
76+ currentUrl . searchParams . set ( "pageSize" , pageSize . toString ( ) ) ;
7577
7678 if ( pushToHistory ) {
7779 window . history . pushState ( null , "" , currentUrl . toString ( ) ) ;
7880 }
7981
8082 setFilters ( passedFilters ) ;
8183 setDataLoaded ( false )
82- fetchLuceneQuery ( passedFilters , sessionId , trackGUID , currentOffset , ( json ) => { handleSearch ( json ) } , ( error ) => { setDataLoaded ( true ) ; setError ( error ) } ) ;
84+ fetchLuceneQuery ( passedFilters , sessionId , trackGUID , page , pageSize , ( json ) => { handleSearch ( json ) } , ( error ) => { setDataLoaded ( true ) ; setError ( error ) } ) ;
8385 }
8486
8587 const TableCellWithPopover = ( props : { value : any } ) => {
@@ -220,6 +222,7 @@ const VariantTableWidget = observer(props => {
220222
221223 const [ filterModalOpen , setFilterModalOpen ] = useState ( false ) ;
222224 const [ filters , setFilters ] = useState ( [ ] ) ;
225+ const [ totalHits , setTotalHits ] = useState ( 0 ) ;
223226 const [ fieldTypeInfo , setFieldTypeInfo ] = useState < FieldModel [ ] > ( [ ] ) ;
224227 const [ allowedGroupNames , setAllowedGroupNames ] = useState < string [ ] > ( [ ] ) ;
225228 const [ promotedFilters , setPromotedFilters ] = useState < Map < string , Filter [ ] > > ( null ) ;
@@ -233,7 +236,10 @@ const VariantTableWidget = observer(props => {
233236 // False until initial data load or an error:
234237 const [ dataLoaded , setDataLoaded ] = useState ( ! parsedLocString )
235238
236- const [ pageSizeModel , setPageSizeModel ] = React . useState < GridPaginationModel > ( { page : 0 , pageSize : 50 } ) ;
239+ const urlParams = new URLSearchParams ( window . location . search ) ;
240+ const page = parseInt ( urlParams . get ( 'page' ) || '0' ) ;
241+ const pageSize = parseInt ( urlParams . get ( 'pageSize' ) || '50' ) ;
242+ const [ pageSizeModel , setPageSizeModel ] = React . useState < GridPaginationModel > ( { page, pageSize } ) ;
237243
238244 // API call to retrieve the requested features.
239245 useEffect ( ( ) => {
@@ -386,7 +392,12 @@ const VariantTableWidget = observer(props => {
386392 columnVisibilityModel = { columnVisibilityModel }
387393 pageSizeOptions = { [ 10 , 25 , 50 , 100 ] }
388394 paginationModel = { pageSizeModel }
389- onPaginationModelChange = { ( newModel ) => setPageSizeModel ( newModel ) }
395+ rowCount = { totalHits }
396+ paginationMode = "server"
397+ onPaginationModelChange = { ( newModel ) => {
398+ setPageSizeModel ( newModel )
399+ handleQuery ( filters , true , newModel )
400+ } }
390401 onColumnVisibilityModelChange = { ( model ) => {
391402 setColumnVisibilityModel ( model )
392403 } }
@@ -470,13 +481,6 @@ const VariantTableWidget = observer(props => {
470481 ) ;
471482 } ) }
472483 </ div >
473-
474- < div style = { { marginLeft : "auto" } } >
475- < ArrowPagination
476- offset = { currentOffset }
477- onOffsetChange = { handleOffsetChange }
478- />
479- </ div >
480484 </ div >
481485
482486 { filterModal }
0 commit comments