@@ -15,14 +15,15 @@ import {
1515 useRegisterBindings ,
1616 type EnsembleAction ,
1717 unwrapWidget ,
18- evaluateDeep ,
18+ useEvaluate ,
1919} from "@ensembleui/react-framework" ;
2020import React , {
2121 useCallback ,
2222 useState ,
2323 useMemo ,
2424 useRef ,
2525 useEffect ,
26+ memo ,
2627} from "react" ;
2728import type { ReactEventHandler , ReactElement } from "react" ;
2829import {
@@ -156,6 +157,42 @@ const ResizableTitle: React.FC<ResizableProps & ResizableState> = (props) => {
156157 ) ;
157158} ;
158159
160+ const CustomRowWithStyles : React . FC <
161+ React . PropsWithChildren < {
162+ "data-index" ?: number ;
163+ "data-styles" ?: EnsembleWidgetStyles ;
164+ "data-record" ?: object ;
165+ [ key : string ] : unknown ;
166+ } >
167+ > = memo (
168+ ( {
169+ "data-index" : index ,
170+ "data-styles" : rowStyles ,
171+ "data-record" : record ,
172+ children,
173+ ...props
174+ } ) => {
175+ const memoizedContext = useMemo (
176+ ( ) => ( { ...record , index } ) ,
177+ [ record , index ] ,
178+ ) ;
179+
180+ const evaluatedRowStyles = useEvaluate (
181+ rowStyles ? ( rowStyles as { [ key : string ] : unknown } ) : undefined ,
182+ {
183+ context : memoizedContext ,
184+ } ,
185+ ) ;
186+
187+ return (
188+ < tr { ...props } style = { { ...evaluatedRowStyles } } >
189+ { children }
190+ </ tr >
191+ ) ;
192+ } ,
193+ ) ;
194+ CustomRowWithStyles . displayName = "CustomRowWithStyles" ;
195+
159196const defaultGridMutatorOptions = {
160197 suppressCallbacks : false ,
161198} ;
@@ -185,11 +222,6 @@ export const DataGrid: React.FC<GridProps> = (props) => {
185222 const selectionColWidth = props . selectionColWidth || 50 ;
186223 const containerRef = useRef < HTMLDivElement > ( null ) ;
187224 const { namedData } = useTemplateData ( { ...itemTemplate } ) ;
188- const components = {
189- header : {
190- cell : ResizableTitle ,
191- } ,
192- } ;
193225
194226 // on row tap action
195227 const onTapAction = useEnsembleAction ( itemTemplate . template . properties . onTap ) ;
@@ -200,6 +232,15 @@ export const DataGrid: React.FC<GridProps> = (props) => {
200232 [ onTapAction ?. callback ] ,
201233 ) ;
202234
235+ const components = {
236+ header : {
237+ cell : ResizableTitle ,
238+ } ,
239+ body : {
240+ row : CustomRowWithStyles ,
241+ } ,
242+ } ;
243+
203244 // on row selected action
204245 const onRowsSelected = useEnsembleAction ( props . onRowsSelected ) ;
205246 const onRowsSelectedCallback = useCallback (
@@ -476,22 +517,14 @@ export const DataGrid: React.FC<GridProps> = (props) => {
476517 dataSource = { namedData }
477518 key = { resolvedWidgetId }
478519 onChange = { onChange }
479- onRow = { ( record , recordIndex ) => {
480- const rowStyles = itemTemplate . template . properties . styles ;
481- const recordStyles = rowStyles
482- ? evaluateDeep (
483- rowStyles as {
484- [ key : string ] : unknown ;
485- } ,
486- defaultScreenContext . model ,
487- { ...record , index : recordIndex } ,
488- )
489- : { } ;
490- return {
491- onClick : ( ) => onTapActionCallback ( record , recordIndex ) ,
492- style : recordStyles ,
493- } ;
494- } }
520+ onRow = { ( record , recordIndex ) => ( {
521+ "data-index" : recordIndex ,
522+ "data-record" : record ,
523+ "data-styles" : itemTemplate . template . properties . styles ,
524+ onClick : itemTemplate . template . properties . onTap
525+ ? ( ) : unknown => onTapActionCallback ( record , recordIndex )
526+ : undefined ,
527+ } ) }
495528 pagination = { paginationObject }
496529 rowKey = { ( data : unknown ) => {
497530 const identifier : string = evaluate (
0 commit comments