11import { Stack , Typography } from '@mui/material' ;
2- import { useGridRootProps } from '@mui/x-data-grid-pro' ;
2+ import {
3+ gridFilteredSortedRowIdsSelector ,
4+ useGridApiContext ,
5+ useGridRootProps ,
6+ useGridSelector ,
7+ } from '@mui/x-data-grid-pro' ;
8+ import { useMemo } from 'react' ;
39import { ChildrenProp , extendSx , StyleProps } from '~/common' ;
410import { FormattedNumber } from '../Formatters' ;
511
612export const Toolbar = ( props : ChildrenProp & StyleProps ) => {
713 const rootProps = useGridRootProps ( ) ;
14+ const apiRef = useGridApiContext ( ) ;
15+ const filteredRowIds = useGridSelector (
16+ apiRef ,
17+ gridFilteredSortedRowIdsSelector
18+ ) ;
19+
20+ const displayCount = useMemo ( ( ) => {
21+ const { items } = rootProps . filterModel ?? { } ;
22+ const hasFilters = items && items . length > 0 ;
23+ const count = hasFilters ? filteredRowIds . length : rootProps . rowCount ;
24+
25+ return count ;
26+ } , [ rootProps . filterModel , filteredRowIds . length , rootProps . rowCount ] ) ;
827
928 return (
1029 < Stack
@@ -24,11 +43,9 @@ export const Toolbar = (props: ChildrenProp & StyleProps) => {
2443 ] }
2544 >
2645 { props . children }
27- { rootProps . rowCount && (
28- < Typography >
29- Total Rows: < FormattedNumber value = { rootProps . rowCount } />
30- </ Typography >
31- ) }
46+ < Typography minWidth = { 100 } >
47+ Total Rows: { displayCount && < FormattedNumber value = { displayCount } /> }
48+ </ Typography >
3249 </ Stack >
3350 ) ;
3451} ;
0 commit comments