@@ -70,7 +70,7 @@ export interface DataGridProps {
7070
7171 readonly accessibilityHeight : number ;
7272
73- readonly freezeColumns : number ;
73+ readonly freezeColumns : number | [ left : number , right : number ] ;
7474 readonly freezeTrailingRows : number ;
7575 readonly hasAppendRow : boolean ;
7676 readonly firstColAccessible : boolean ;
@@ -393,7 +393,9 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
393393 } = p ;
394394 const translateX = p . translateX ?? 0 ;
395395 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 ) ) ;
397399
398400 const ref = React . useRef < HTMLCanvasElement | null > ( null ) ;
399401 const windowEventTargetRef = React . useRef < Document | Window > ( window ) ;
@@ -440,7 +442,10 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
440442 } , [ cellYOffset , cellXOffset , translateX , translateY , enableFirefoxRescaling , enableSafariRescaling ] ) ;
441443
442444 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+ ) ;
444449
445450 // row: -1 === columnHeader, -2 === groupHeader
446451 const getBoundsForItem = React . useCallback (
@@ -465,7 +470,7 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
465470 translateX ,
466471 translateY ,
467472 rows ,
468- freezeColumns ,
473+ freezeLeftColumns ,
469474 freezeTrailingRows ,
470475 mappedColumns ,
471476 rowHeight
@@ -493,7 +498,7 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
493498 translateX ,
494499 translateY ,
495500 rows ,
496- freezeColumns ,
501+ freezeLeftColumns ,
497502 freezeTrailingRows ,
498503 mappedColumns ,
499504 rowHeight ,
@@ -508,7 +513,14 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
508513 const y = ( posY - rect . top ) / scale ;
509514 const edgeDetectionBuffer = 5 ;
510515
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+ ) ;
512524
513525 let button = 0 ;
514526 let buttons = 0 ;
@@ -518,7 +530,7 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
518530 }
519531
520532 // -1 === off right edge
521- const col = getColumnIndexForX ( x , effectiveCols , translateX ) ;
533+ const col = getColumnIndexForX ( x , effectiveCols , freezeColumns , width , translateX ) ;
522534
523535 // -1: header or above
524536 // undefined: offbottom
@@ -686,6 +698,7 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
686698 fillHandle ,
687699 selection ,
688700 totalHeaderHeight ,
701+ freezeColumns ,
689702 ]
690703 ) ;
691704
@@ -1717,7 +1730,14 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
17171730 const accessibilityTree = useDebouncedMemo (
17181731 ( ) => {
17191732 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+ ) ;
17211741 const colOffset = firstColAccessible ? 0 : - 1 ;
17221742 if ( ! firstColAccessible && effectiveCols [ 0 ] ?. sourceIndex === 0 ) {
17231743 effectiveCols = effectiveCols . slice ( 1 ) ;
@@ -1851,33 +1871,59 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
18511871 onKeyDown ,
18521872 getBoundsForItem ,
18531873 onCellFocused ,
1874+ freezeColumns ,
18541875 ] ,
18551876 200
18561877 ) ;
18571878
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 ) ;
18601892
18611893 const absoluteOffsetY = - cellYOffset * 32 + translateY ;
18621894 const opacityY = ! fixedShadowY ? 0 : clamp ( - absoluteOffsetY / 100 , 0 , 1 ) ;
18631895
18641896 const stickyShadow = React . useMemo ( ( ) => {
1865- if ( ! opacityX && ! opacityY ) {
1897+ if ( ! opacityXLeft && ! opacityY && ! opacityXRight ) {
18661898 return null ;
18671899 }
18681900
1869- const styleX : React . CSSProperties = {
1901+ const transition = "opacity 0.2s" ;
1902+
1903+ const styleXLeft : React . CSSProperties = {
18701904 position : "absolute" ,
18711905 top : 0 ,
1872- left : stickyX ,
1873- width : width - stickyX ,
1906+ left : stickyX [ 0 ] ,
1907+ width : width - stickyX [ 0 ] ,
18741908 height : height ,
1875- opacity : opacityX ,
1909+ opacity : opacityXLeft ,
18761910 pointerEvents : "none" ,
1877- transition : ! smoothScrollX ? "opacity 0.2s" : undefined ,
1911+ transition : ! smoothScrollX ? transition : undefined ,
18781912 boxShadow : "inset 13px 0 10px -13px rgba(0, 0, 0, 0.2)" ,
18791913 } ;
18801914
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+
18811927 const styleY : React . CSSProperties = {
18821928 position : "absolute" ,
18831929 top : totalHeaderHeight ,
@@ -1886,17 +1932,28 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
18861932 height : height ,
18871933 opacity : opacityY ,
18881934 pointerEvents : "none" ,
1889- transition : ! smoothScrollY ? "opacity 0.2s" : undefined ,
1935+ transition : ! smoothScrollY ? transition : undefined ,
18901936 boxShadow : "inset 0 13px 10px -13px rgba(0, 0, 0, 0.2)" ,
18911937 } ;
18921938
18931939 return (
18941940 < >
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 } /> }
18961943 { opacityY > 0 && < div id = "shadow-y" style = { styleY } /> }
18971944 </ >
18981945 ) ;
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+ ] ) ;
19001957
19011958 const overlayStyle = React . useMemo < React . CSSProperties > (
19021959 ( ) => ( {
0 commit comments