Last active
March 6, 2021 08:43
-
-
Save dcts/76c74cbecdcae3e3aec15e40ad7c101b to your computer and use it in GitHub Desktop.
gridjs get Grid instance to change data programatically
This file contains hidden or 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 { Grid } from 'gridjs-react'; | |
import { useRef } from "react"; | |
const MyComponent = () => { | |
const gridRef = useRef(); | |
const changeMyGrid = () => { | |
const gridjsInstance = gridRef.current.getInstance(); | |
// update col names | |
gridjsInstance.updateConfig({ | |
columns: ["First Name", "Last Name"], | |
}) | |
// force render to make changes visible | |
gridjsInstance.forceRender(); | |
} | |
return ( | |
<div> | |
<button onClick={changeMyGrid}>Switch To English</button> | |
<Grid | |
ref={gridRef} | |
data={[ | |
["Martin", "Meister"], | |
["Hans", "Ruedi"], | |
["Simone", "Johnson"], | |
]} | |
columns={["Vorname", "Nachname"]} | |
search={true} | |
/> | |
</div> | |
); | |
}; | |
export default MyComponent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing it