|
| 1 | +--- |
| 2 | +title: Configuration |
| 3 | +--- |
| 4 | + |
| 5 | +In order to use a Grid.js instance, you need to configure it first. Grid.js accepts a configuration object which can be updated using: |
| 6 | + |
| 7 | + - `Grid` constructor |
| 8 | + - `updateConfig` method |
| 9 | + |
| 10 | + |
| 11 | +## `Grid` constructor |
| 12 | + |
| 13 | +Simply pass your configuration object to the `Grid` constructor to configure the instance. It is possible to update this |
| 14 | +config later on. |
| 15 | + |
| 16 | +```js |
| 17 | +new Grid({ |
| 18 | + columns: ['Name', 'Email', 'Phone Number'], |
| 19 | + data: [ |
| 20 | + ['John', 'john@example.com', '(353) 01 222 3333'], |
| 21 | + ['Mark', 'mark@gmail.com', '(01) 22 888 4444'] |
| 22 | + ] |
| 23 | +}); |
| 24 | +``` |
| 25 | + |
| 26 | +:::info |
| 27 | +A full list of config object properties is defined in the [Config](./config/data.md) section of this document |
| 28 | +::: |
| 29 | + |
| 30 | + |
| 31 | +## `updateConfig` |
| 32 | + |
| 33 | +It is also possible to create an empty Grid.js instance and update the configs later on (and before calling the `render` method): |
| 34 | + |
| 35 | +```js |
| 36 | +new Grid().updateConfig({ |
| 37 | + columns: ['Name', 'Email', 'Phone Number'], |
| 38 | + data: [ |
| 39 | + ['John', 'john@example.com', '(353) 01 222 3333'], |
| 40 | + ['Mark', 'mark@gmail.com', '(01) 22 888 4444'] |
| 41 | + ] |
| 42 | +}); |
| 43 | +``` |
| 44 | + |
| 45 | +Or to just simply update an existing key in the config object: |
| 46 | + |
| 47 | +```js |
| 48 | +new Grid({ |
| 49 | + columns: ['Name', 'Email', 'Phone Number'], |
| 50 | + data: [ |
| 51 | + ['John', 'john@example.com', '(353) 01 222 3333'], |
| 52 | + ['Mark', 'mark@gmail.com', '(01) 22 888 4444'] |
| 53 | + ] |
| 54 | +}).updateConfig({ |
| 55 | + // lets update the columns field only |
| 56 | + columns: ['First Name', 'Email', 'Phone'] |
| 57 | +}); |
| 58 | +``` |
| 59 | + |
| 60 | +:::tip |
| 61 | +The [examples directory](./examples/hello-world.md) has an interactive editor that |
| 62 | +you can use to see the effect config properties live. |
| 63 | +::: |
| 64 | + |
0 commit comments