@@ -19,6 +19,7 @@ import {
1919 EuiDataGridPaginationProps ,
2020 EuiDataGridSorting ,
2121 EuiDataGridColumnSortingConfig ,
22+ RenderCellValue ,
2223} from '../../../../../src' ;
2324
2425const raw_data : Array < { [ key : string ] : string } > = [ ] ;
@@ -67,6 +68,14 @@ const columns = [
6768 } ,
6869] ;
6970
71+ const checkboxRowCellRender : RenderCellValue = ( { rowIndex } ) => (
72+ < EuiCheckbox
73+ id = { `select-row-${ rowIndex } ` }
74+ aria-label = "Select row"
75+ onChange = { ( ) => { } }
76+ />
77+ ) ;
78+
7079const leadingControlColumns : EuiDataGridProps [ 'leadingControlColumns' ] = [
7180 {
7281 id : 'selection' ,
@@ -78,13 +87,7 @@ const leadingControlColumns: EuiDataGridProps['leadingControlColumns'] = [
7887 onChange = { ( ) => { } }
7988 />
8089 ) ,
81- rowCellRender : ( { rowIndex } ) => (
82- < EuiCheckbox
83- id = { `select-row-${ rowIndex } ` }
84- aria-label = "Select row"
85- onChange = { ( ) => { } }
86- />
87- ) ,
90+ rowCellRender : checkboxRowCellRender ,
8891 } ,
8992] ;
9093
@@ -103,6 +106,22 @@ const trailingControlColumns: EuiDataGridProps['trailingControlColumns'] = [
103106 } ,
104107] ;
105108
109+ const RowCellRender : RenderCellValue = ( { setCellProps, rowIndex } ) => {
110+ setCellProps ( { style : { width : '100%' , height : 'auto' } } ) ;
111+
112+ const firstName = raw_data [ rowIndex ] . name . split ( ', ' ) [ 1 ] ;
113+ const isGood = faker . datatype . boolean ( ) ;
114+ return (
115+ < >
116+ { firstName } 's account has { isGood ? 'no' : '' } outstanding fees.{ ' ' }
117+ < EuiIcon
118+ type = { isGood ? 'checkInCircleFilled' : 'error' }
119+ color = { isGood ? 'success' : 'danger' }
120+ />
121+ </ >
122+ ) ;
123+ } ;
124+
106125// The custom row details is actually a trailing control column cell with
107126// a hidden header. This is important for accessibility and markup reasons
108127// @see https://fuschia-stretch.glitch.me/ for more
@@ -120,21 +139,7 @@ const rowDetails: EuiDataGridProps['trailingControlColumns'] = [
120139
121140 // When rendering this custom cell, we'll want to override
122141 // the automatic width/heights calculated by EuiDataGrid
123- rowCellRender : ( { setCellProps, rowIndex } ) => {
124- setCellProps ( { style : { width : '100%' , height : 'auto' } } ) ;
125-
126- const firstName = raw_data [ rowIndex ] . name . split ( ', ' ) [ 1 ] ;
127- const isGood = faker . datatype . boolean ( ) ;
128- return (
129- < >
130- { firstName } 's account has { isGood ? 'no' : '' } outstanding fees.{ ' ' }
131- < EuiIcon
132- type = { isGood ? 'checkInCircleFilled' : 'error' }
133- color = { isGood ? 'success' : 'danger' }
134- />
135- </ >
136- ) ;
137- } ,
142+ rowCellRender : RowCellRender ,
138143 } ,
139144] ;
140145
@@ -144,10 +149,10 @@ const footerCellValues: { [key: string]: string } = {
144149 . toLocaleString ( 'en-US' , { style : 'currency' , currency : 'USD' } ) } `,
145150} ;
146151
147- const RenderFooterCellValue : EuiDataGridProps [ 'renderFooterCellValue' ] = ( {
148- columnId,
149- setCellProps ,
150- } ) => {
152+ const renderCellValue : RenderCellValue = ( { rowIndex , columnId } ) =>
153+ raw_data [ rowIndex ] [ columnId ] ;
154+
155+ const RenderFooterCellValue : RenderCellValue = ( { columnId , setCellProps } ) => {
151156 const value = footerCellValues [ columnId ] ;
152157
153158 useEffect ( ( ) => {
@@ -298,9 +303,7 @@ export default () => {
298303 onChangeItemsPerPage : onChangePageSize ,
299304 } }
300305 rowCount = { raw_data . length }
301- renderCellValue = { ( { rowIndex, columnId } ) =>
302- raw_data [ rowIndex ] [ columnId ]
303- }
306+ renderCellValue = { renderCellValue }
304307 renderFooterCellValue = { RenderFooterCellValue }
305308 renderCustomGridBody = { RenderCustomGridBody }
306309 height = { autoHeight ? undefined : 400 }
0 commit comments