Skip to content

Commit 5c517c5

Browse files
committed
feat: force-render
1 parent 8a27ba0 commit 5c517c5

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
lines changed

docs/examples/force-render.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
id: force-render
3+
title: forceRender
4+
---
5+
6+
import { Grid } from "gridjs";
7+
import CodeBlock from "@theme/CodeBlock"
8+
import { useEffect, useRef } from "react";
9+
10+
11+
Using `updateConfig()` and `forceUpdate()` function, you can update the config of an existing instance and re-render the
12+
container.
13+
14+
In this example, we render a Grid.js instance, and then we attempt to update the config object and re-render it after 2 seconds:
15+
16+
<CodeBlock children={
17+
`
18+
function () {
19+
const wrapper = useRef(null);
20+
21+
useEffect(() => {
22+
// initial setup
23+
const grid = new Grid({
24+
columns: ['Name', 'Email', 'Phone Number'],
25+
data: [
26+
['John', '[email protected]', '(353) 01 222 3333'],
27+
]
28+
}).render(wrapper.current);
29+
30+
setTimeout(() => {
31+
// lets update the config
32+
grid.updateConfig({
33+
search: true,
34+
data: [
35+
['John', '[email protected]', '(353) 01 222 3333'],
36+
['Mark', '[email protected]', '(01) 22 888 4444'],
37+
]
38+
}).forceRender();
39+
}, 2000);
40+
});
41+
42+
return (
43+
<div ref={wrapper} />
44+
);
45+
}
46+
`
47+
} live={true} scope={{ Grid, CodeBlock, useEffect, useRef }} />

docs/examples/from.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function () {
3737
</tr>
3838
<tr>
3939
<td>Mike</td>
40-
40+
<td><b>[email protected]</b></td>
4141
</tr>
4242
</tbody>
4343
</table>

docs/examples/hello-world.md

+35-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: Hello, World!
55

66
import { Grid } from "gridjs";
77
import CodeBlock from "@theme/CodeBlock"
8-
import { useEffect } from "react";
8+
import { useEffect, useRef } from "react";
99

1010
:::tip
1111
You can interact with the following editor!
@@ -38,3 +38,37 @@ function () {
3838
`
3939
} live={true} scope={{ Grid, CodeBlock, useEffect }} />
4040

41+
<br/>
42+
43+
Or you can update the config using `updateConfig`:
44+
45+
<CodeBlock children={
46+
`
47+
const grid = new Grid({
48+
data: [
49+
['John', '[email protected]', '(353) 01 222 3333'],
50+
['Mark', '[email protected]', '(01) 22 888 4444']
51+
]
52+
}).updateConfig({
53+
columns: ['Name', 'Email', 'Phone Number'],
54+
});
55+
`
56+
}
57+
transformCode={(code) =>
58+
`
59+
function () {
60+
const wrapper = useRef(null);
61+
62+
${code}
63+
64+
useEffect(() => {
65+
grid.render(wrapper.current);
66+
});
67+
68+
return (
69+
<div id="wrapper" ref={wrapper} />
70+
);
71+
}
72+
`
73+
} live={true} scope={{ Grid, CodeBlock, useEffect, useRef }} />
74+

sidebars.js

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ module.exports = {
4141
type: 'category',
4242
label: 'Advanced',
4343
items: [
44+
'examples/force-render',
4445
'examples/cell-formatting',
4546
'examples/html-cells',
4647
'examples/multi-sort',

0 commit comments

Comments
 (0)