@@ -6,9 +6,11 @@ import {
6
6
type MRT_TableOptions ,
7
7
MaterialReactTable ,
8
8
createRow ,
9
+ MRT_Row ,
9
10
} from '../../src' ;
10
11
import { faker } from '@faker-js/faker' ;
11
12
import { type Meta } from '@storybook/react' ;
13
+ import { MenuItem , Select } from '@mui/material' ;
12
14
13
15
const meta : Meta = {
14
16
title : 'Features/Creating Examples' ,
@@ -338,3 +340,65 @@ export const CreateRowIndexIndexExpanding = () => {
338
340
/>
339
341
) ;
340
342
} ;
343
+
344
+ export const CreateWithCustomEditCell = ( ) => {
345
+ const [ tableData , setTableData ] = useState ( data ) ;
346
+
347
+ const handleSaveRow : MRT_TableOptions < Person > [ 'onEditingRowSave' ] = ( {
348
+ exitEditingMode,
349
+ row,
350
+ values,
351
+ } ) => {
352
+ tableData [ row . index ] = values ;
353
+ setTableData ( [ ...tableData ] ) ;
354
+ exitEditingMode ( ) ;
355
+ } ;
356
+
357
+ const [ creatingRow , setCreatingRow ] = useState < MRT_Row < Person > | null > ( null ) ;
358
+
359
+ return (
360
+ < MaterialReactTable
361
+ columns = { [
362
+ {
363
+ accessorKey : 'firstName' ,
364
+ header : 'First Name' ,
365
+ } ,
366
+ {
367
+ accessorKey : 'lastName' ,
368
+ header : 'Last Name' ,
369
+ } ,
370
+ {
371
+ accessorKey : 'address' ,
372
+ header : 'Address' ,
373
+ } ,
374
+ {
375
+ accessorKey : 'state' ,
376
+ header : 'State' ,
377
+ Edit : ( { cell } ) => (
378
+ < Select value = { cell . getValue < string > ( ) } >
379
+ < MenuItem value = "Alabama" > Alabama</ MenuItem >
380
+ < MenuItem value = "Alaska" > Alaska</ MenuItem >
381
+ </ Select >
382
+ ) ,
383
+ } ,
384
+ {
385
+ accessorKey : 'phoneNumber' ,
386
+ enableEditing : false ,
387
+ header : 'Phone Number' ,
388
+ } ,
389
+ ] }
390
+ state = { { creatingRow } }
391
+ onCreatingRowChange = { setCreatingRow }
392
+ createDisplayMode = "row"
393
+ data = { tableData }
394
+ editDisplayMode = "row"
395
+ enableEditing = { ( row ) => row . id === creatingRow ?. id }
396
+ onCreatingRowSave = { ( ) => { } }
397
+ onEditingRowSave = { handleSaveRow }
398
+ positionCreatingRow = "top"
399
+ renderTopToolbarCustomActions = { ( { table } ) => (
400
+ < Button onClick = { ( ) => table . setCreatingRow ( true ) } > Add</ Button >
401
+ ) }
402
+ />
403
+ ) ;
404
+ } ;
0 commit comments