Last active
February 5, 2021 10:14
-
-
Save raphael-leger/d27e2914746e8e881e8c0d6426fd0a6d to your computer and use it in GitHub Desktop.
React and tui.grid : how to remove a row
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from 'react'; | |
import Grid from '@toast-ui/react-grid'; | |
import RemoveButtonRenderer from './RemoveButtonRenderer.jsx'; | |
const Table = () => { | |
const [fruits, setFruits] = useState([ | |
{ | |
name: 'apple', | |
color: 'green', | |
size: 'medium' | |
}, { | |
name: 'banana', | |
color: 'yellow', | |
size: 'medium' | |
}, { | |
name: 'tomato', | |
color: 'red', | |
size: 'small' | |
} | |
]); | |
const onRemoveButtonClicked = (rowIndex) => { | |
const updatedFruits = [...fruits]; | |
updatedFruits.splice(rowIndex, 1); | |
setFruits(updatedFruits); | |
}; | |
const columns = [ | |
{ | |
header: 'Fruit name', | |
name: 'name' | |
}, | |
{ | |
header: 'Fruit color', | |
name: 'color' | |
}, | |
{ | |
header: 'Fruit size', | |
name: 'size' | |
}, | |
{ | |
header: ' ', | |
name: 'removeRow', | |
align: 'center', | |
width: 20, | |
renderer: { | |
type: RemoveButtonRenderer, | |
options: { | |
onRemoveButtonClicked | |
} | |
} | |
} | |
]; | |
return ( | |
<Grid | |
data={fruits} | |
columns={columns} | |
/> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment