Skip to content

Instantly share code, notes, and snippets.

@dcts
Last active March 6, 2021 08:43
Show Gist options
  • Save dcts/76c74cbecdcae3e3aec15e40ad7c101b to your computer and use it in GitHub Desktop.
Save dcts/76c74cbecdcae3e3aec15e40ad7c101b to your computer and use it in GitHub Desktop.
gridjs get Grid instance to change data programatically
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;
@sauloquirino
Copy link

Thanks for sharing it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment