11import { Stack , Typography } from '@mui/material' ;
2- import { useGridRootProps } from '@mui/x-data-grid-pro' ;
2+ import {
3+ gridFilteredSortedRowIdsSelector ,
4+ gridFilterModelSelector ,
5+ useGridApiContext ,
6+ useGridRootProps ,
7+ useGridSelector ,
8+ } from '@mui/x-data-grid-pro' ;
9+ import { useMemo } from 'react' ;
310import { ChildrenProp , extendSx , StyleProps } from '~/common' ;
411import { FormattedNumber } from '../Formatters' ;
512
613export const Toolbar = ( props : ChildrenProp & StyleProps ) => {
714 const rootProps = useGridRootProps ( ) ;
15+ const apiRef = useGridApiContext ( ) ;
16+ const filteredRowIds = useGridSelector (
17+ apiRef ,
18+ gridFilteredSortedRowIdsSelector
19+ ) ;
20+ const filterModel = useGridSelector ( apiRef , gridFilterModelSelector ) ;
21+
22+ const displayCount = useMemo ( ( ) => {
23+ const { items } = filterModel ;
24+ const hasFilters = items . length > 0 ;
25+ const count = hasFilters ? filteredRowIds . length : rootProps . rowCount ;
26+
27+ return count ;
28+ } , [ filterModel , filteredRowIds . length , rootProps . rowCount ] ) ;
829
930 return (
1031 < Stack
@@ -24,11 +45,9 @@ export const Toolbar = (props: ChildrenProp & StyleProps) => {
2445 ] }
2546 >
2647 { props . children }
27- { rootProps . rowCount && (
28- < Typography >
29- Total Rows: < FormattedNumber value = { rootProps . rowCount } />
30- </ Typography >
31- ) }
48+ < Typography minWidth = { 100 } >
49+ Total Rows: { displayCount && < FormattedNumber value = { displayCount } /> }
50+ </ Typography >
3251 </ Stack >
3352 ) ;
3453} ;
0 commit comments