@@ -70,7 +70,7 @@ export interface DataGridProps {
70
70
71
71
readonly accessibilityHeight : number ;
72
72
73
- readonly freezeColumns : number ;
73
+ readonly freezeColumns : number | [ left : number , right : number ] ;
74
74
readonly freezeTrailingRows : number ;
75
75
readonly hasAppendRow : boolean ;
76
76
readonly firstColAccessible : boolean ;
@@ -393,7 +393,9 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
393
393
} = p ;
394
394
const translateX = p . translateX ?? 0 ;
395
395
const translateY = p . translateY ?? 0 ;
396
- const cellXOffset = Math . max ( freezeColumns , Math . min ( columns . length - 1 , cellXOffsetReal ) ) ;
396
+ const freezeLeftColumns = typeof freezeColumns === "number" ? freezeColumns : freezeColumns [ 0 ] ;
397
+ const freezeRightColumns = typeof freezeColumns === "number" ? 0 : freezeColumns [ 1 ] ;
398
+ const cellXOffset = Math . max ( freezeLeftColumns , Math . min ( columns . length - 1 , cellXOffsetReal ) ) ;
397
399
398
400
const ref = React . useRef < HTMLCanvasElement | null > ( null ) ;
399
401
const windowEventTargetRef = React . useRef < Document | Window > ( window ) ;
@@ -440,7 +442,10 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
440
442
} , [ cellYOffset , cellXOffset , translateX , translateY , enableFirefoxRescaling , enableSafariRescaling ] ) ;
441
443
442
444
const mappedColumns = useMappedColumns ( columns , freezeColumns ) ;
443
- const stickyX = fixedShadowX ? getStickyWidth ( mappedColumns , dragAndDropState ) : 0 ;
445
+ const stickyX = React . useMemo (
446
+ ( ) => ( fixedShadowX ? getStickyWidth ( mappedColumns , dragAndDropState ) : [ 0 , 0 ] ) ,
447
+ [ fixedShadowX , mappedColumns , dragAndDropState ]
448
+ ) ;
444
449
445
450
// row: -1 === columnHeader, -2 === groupHeader
446
451
const getBoundsForItem = React . useCallback (
@@ -465,7 +470,7 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
465
470
translateX ,
466
471
translateY ,
467
472
rows ,
468
- freezeColumns ,
473
+ freezeLeftColumns ,
469
474
freezeTrailingRows ,
470
475
mappedColumns ,
471
476
rowHeight
@@ -493,7 +498,7 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
493
498
translateX ,
494
499
translateY ,
495
500
rows ,
496
- freezeColumns ,
501
+ freezeLeftColumns ,
497
502
freezeTrailingRows ,
498
503
mappedColumns ,
499
504
rowHeight ,
@@ -508,7 +513,14 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
508
513
const y = ( posY - rect . top ) / scale ;
509
514
const edgeDetectionBuffer = 5 ;
510
515
511
- const effectiveCols = getEffectiveColumns ( mappedColumns , cellXOffset , width , undefined , translateX ) ;
516
+ const effectiveCols = getEffectiveColumns (
517
+ mappedColumns ,
518
+ cellXOffset ,
519
+ width ,
520
+ freezeColumns ,
521
+ undefined ,
522
+ translateX
523
+ ) ;
512
524
513
525
let button = 0 ;
514
526
let buttons = 0 ;
@@ -518,7 +530,7 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
518
530
}
519
531
520
532
// -1 === off right edge
521
- const col = getColumnIndexForX ( x , effectiveCols , translateX ) ;
533
+ const col = getColumnIndexForX ( x , effectiveCols , freezeColumns , width , translateX ) ;
522
534
523
535
// -1: header or above
524
536
// undefined: offbottom
@@ -686,6 +698,7 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
686
698
fillHandle ,
687
699
selection ,
688
700
totalHeaderHeight ,
701
+ freezeColumns ,
689
702
]
690
703
) ;
691
704
@@ -1717,7 +1730,14 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
1717
1730
const accessibilityTree = useDebouncedMemo (
1718
1731
( ) => {
1719
1732
if ( width < 50 || experimental ?. disableAccessibilityTree === true ) return null ;
1720
- let effectiveCols = getEffectiveColumns ( mappedColumns , cellXOffset , width , dragAndDropState , translateX ) ;
1733
+ let effectiveCols = getEffectiveColumns (
1734
+ mappedColumns ,
1735
+ cellXOffset ,
1736
+ width ,
1737
+ freezeColumns ,
1738
+ dragAndDropState ,
1739
+ translateX
1740
+ ) ;
1721
1741
const colOffset = firstColAccessible ? 0 : - 1 ;
1722
1742
if ( ! firstColAccessible && effectiveCols [ 0 ] ?. sourceIndex === 0 ) {
1723
1743
effectiveCols = effectiveCols . slice ( 1 ) ;
@@ -1851,33 +1871,59 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
1851
1871
onKeyDown ,
1852
1872
getBoundsForItem ,
1853
1873
onCellFocused ,
1874
+ freezeColumns ,
1854
1875
] ,
1855
1876
200
1856
1877
) ;
1857
1878
1858
- const opacityX =
1859
- freezeColumns === 0 || ! fixedShadowX ? 0 : cellXOffset > freezeColumns ? 1 : clamp ( - translateX / 100 , 0 , 1 ) ;
1879
+ const opacityXLeft =
1880
+ freezeLeftColumns === 0 || ! fixedShadowX
1881
+ ? 0
1882
+ : cellXOffset > freezeLeftColumns
1883
+ ? 1
1884
+ : clamp ( - translateX / 100 , 0 , 1 ) ;
1885
+
1886
+ const opacityXRight =
1887
+ freezeRightColumns === 0 || ! fixedShadowX
1888
+ ? 0
1889
+ : cellXOffset + width < columns . length - freezeRightColumns
1890
+ ? 1
1891
+ : clamp ( ( translateX - ( columns . length - freezeRightColumns - width ) * 32 ) / 100 , 0 , 1 ) ;
1860
1892
1861
1893
const absoluteOffsetY = - cellYOffset * 32 + translateY ;
1862
1894
const opacityY = ! fixedShadowY ? 0 : clamp ( - absoluteOffsetY / 100 , 0 , 1 ) ;
1863
1895
1864
1896
const stickyShadow = React . useMemo ( ( ) => {
1865
- if ( ! opacityX && ! opacityY ) {
1897
+ if ( ! opacityXLeft && ! opacityY && ! opacityXRight ) {
1866
1898
return null ;
1867
1899
}
1868
1900
1869
- const styleX : React . CSSProperties = {
1901
+ const transition = "opacity 0.2s" ;
1902
+
1903
+ const styleXLeft : React . CSSProperties = {
1870
1904
position : "absolute" ,
1871
1905
top : 0 ,
1872
- left : stickyX ,
1873
- width : width - stickyX ,
1906
+ left : stickyX [ 0 ] ,
1907
+ width : width - stickyX [ 0 ] ,
1874
1908
height : height ,
1875
- opacity : opacityX ,
1909
+ opacity : opacityXLeft ,
1876
1910
pointerEvents : "none" ,
1877
- transition : ! smoothScrollX ? "opacity 0.2s" : undefined ,
1911
+ transition : ! smoothScrollX ? transition : undefined ,
1878
1912
boxShadow : "inset 13px 0 10px -13px rgba(0, 0, 0, 0.2)" ,
1879
1913
} ;
1880
1914
1915
+ const styleXRight : React . CSSProperties = {
1916
+ position : "absolute" ,
1917
+ top : 0 ,
1918
+ right : stickyX [ 1 ] ,
1919
+ width : width - stickyX [ 1 ] ,
1920
+ height : height ,
1921
+ opacity : opacityXRight ,
1922
+ pointerEvents : "none" ,
1923
+ transition : ! smoothScrollX ? transition : undefined ,
1924
+ boxShadow : "inset -13px 0 10px -13px rgba(0, 0, 0, 0.2)" ,
1925
+ } ;
1926
+
1881
1927
const styleY : React . CSSProperties = {
1882
1928
position : "absolute" ,
1883
1929
top : totalHeaderHeight ,
@@ -1886,17 +1932,28 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
1886
1932
height : height ,
1887
1933
opacity : opacityY ,
1888
1934
pointerEvents : "none" ,
1889
- transition : ! smoothScrollY ? "opacity 0.2s" : undefined ,
1935
+ transition : ! smoothScrollY ? transition : undefined ,
1890
1936
boxShadow : "inset 0 13px 10px -13px rgba(0, 0, 0, 0.2)" ,
1891
1937
} ;
1892
1938
1893
1939
return (
1894
1940
< >
1895
- { opacityX > 0 && < div id = "shadow-x" style = { styleX } /> }
1941
+ { opacityXLeft > 0 && < div id = "shadow-x" style = { styleXLeft } /> }
1942
+ { opacityXRight > 0 && < div id = "shadow-x" style = { styleXRight } /> }
1896
1943
{ opacityY > 0 && < div id = "shadow-y" style = { styleY } /> }
1897
1944
</ >
1898
1945
) ;
1899
- } , [ opacityX , opacityY , stickyX , width , smoothScrollX , totalHeaderHeight , height , smoothScrollY ] ) ;
1946
+ } , [
1947
+ opacityXLeft ,
1948
+ opacityY ,
1949
+ stickyX ,
1950
+ width ,
1951
+ smoothScrollX ,
1952
+ totalHeaderHeight ,
1953
+ height ,
1954
+ smoothScrollY ,
1955
+ opacityXRight ,
1956
+ ] ) ;
1900
1957
1901
1958
const overlayStyle = React . useMemo < React . CSSProperties > (
1902
1959
( ) => ( {
0 commit comments