@@ -355,9 +355,12 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
355355 setEditValue ( currentValue ?? '' ) ;
356356 } ;
357357
358- const saveEdit = ( ) => {
358+ const saveEdit = ( force : boolean = false ) => {
359359 if ( ! editingCell ) return ;
360360
361+ // Don't save if we're in cancelled state (unless forced)
362+ if ( ! force && editingCell === null ) return ;
363+
361364 const { rowIndex, columnKey } = editingCell ;
362365 const globalIndex = ( currentPage - 1 ) * pageSize + rowIndex ;
363366 const row = sortedData [ globalIndex ] ;
@@ -379,6 +382,9 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
379382 const handleCellKeyDown = ( e : React . KeyboardEvent , rowIndex : number , columnKey : string ) => {
380383 if ( ! editable ) return ;
381384
385+ const column = columns . find ( col => col . accessorKey === columnKey ) ;
386+ if ( column ?. editable === false ) return ;
387+
382388 if ( e . key === 'Enter' && ! editingCell ) {
383389 e . preventDefault ( ) ;
384390 const value = paginatedData [ rowIndex ] [ columnKey ] ;
@@ -389,7 +395,7 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
389395 const handleEditKeyDown = ( e : React . KeyboardEvent ) => {
390396 if ( e . key === 'Enter' ) {
391397 e . preventDefault ( ) ;
392- saveEdit ( ) ;
398+ saveEdit ( true ) ;
393399 } else if ( e . key === 'Escape' ) {
394400 e . preventDefault ( ) ;
395401 cancelEdit ( ) ;
@@ -596,15 +602,14 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
596602 } }
597603 onDoubleClick = { ( ) => isEditable && startEdit ( rowIndex , col . accessorKey , cellValue ) }
598604 onKeyDown = { ( e ) => handleCellKeyDown ( e , rowIndex , col . accessorKey ) }
599- tabIndex = { isEditable ? 0 : - 1 }
605+ tabIndex = { 0 }
600606 >
601607 { isEditing ? (
602608 < Input
603609 ref = { editInputRef }
604610 value = { editValue }
605611 onChange = { ( e ) => setEditValue ( e . target . value ) }
606612 onKeyDown = { handleEditKeyDown }
607- onBlur = { saveEdit }
608613 className = "h-8 px-2 py-1"
609614 />
610615 ) : (
0 commit comments