|
| 1 | +## 1. Install ReactGrid from npm repository |
| 2 | + |
| 3 | +```shell |
| 4 | +npm i @silevis/reactgrid |
| 5 | +``` |
| 6 | + |
| 7 | +## 2. Import ReactGrid component |
| 8 | + |
| 9 | +```tsx |
| 10 | +import { ReactGrid } from "@silevis/reactgrid"; |
| 11 | +``` |
| 12 | + |
| 13 | +## 3. Import css styles |
| 14 | + |
| 15 | +Import file from `node_modules` directory. This file is necessary to correctly displaying. |
| 16 | + |
| 17 | +```tsx |
| 18 | +import "@silevis/reactgrid/dist/lib/assets/core.css"; |
| 19 | +``` |
| 20 | + |
| 21 | +## 4. Create a cell matrix |
| 22 | + |
| 23 | +Time to define our data. It will be stored in [React Hook](https://reactjs.org/docs/hooks-intro.html). |
| 24 | +`useState` hook will be initialized with object that contains two keys - `columns` and `rows`. |
| 25 | +Both of them must be valid ReactGrid objects: `Columns` `Rows`. |
| 26 | + |
| 27 | +```tsx |
| 28 | +import React, { useState } from "react"; |
| 29 | +import ReactDOM from "react-dom"; |
| 30 | +import { ReactGrid } from "@silevis/reactgrid"; |
| 31 | +import "@silevis/reactgrid/dist/lib/assets/core.css"; |
| 32 | + |
| 33 | +function App() { |
| 34 | + const [state, setState] = useState(() => ({ |
| 35 | + columns: [ |
| 36 | + { columnId: "Name", width: 100 }, |
| 37 | + { columnId: "Surname", width: 100 } |
| 38 | + ], |
| 39 | + rows: [ |
| 40 | + { |
| 41 | + rowId: 0, |
| 42 | + cells: [ |
| 43 | + { type: "header", text: "Name" }, |
| 44 | + { type: "header", text: "Surname" } |
| 45 | + ] |
| 46 | + }, |
| 47 | + { |
| 48 | + rowId: 1, |
| 49 | + cells: [ |
| 50 | + { type: "text", text: "Thomas" }, |
| 51 | + { type: "text", text: "Goldman" } |
| 52 | + ] |
| 53 | + }, |
| 54 | + { |
| 55 | + rowId: 2, |
| 56 | + cells: [ |
| 57 | + { type: "text", text: "Susie" }, |
| 58 | + { type: "text", text: "Spencer" } |
| 59 | + ] |
| 60 | + }, |
| 61 | + { |
| 62 | + rowId: 2, |
| 63 | + cells: [{ type: "text", text: "" }, { type: "text", text: "" }] |
| 64 | + } |
| 65 | + ] |
| 66 | + })); |
| 67 | + |
| 68 | + return ( |
| 69 | + <ReactGrid |
| 70 | + rows={state.rows} |
| 71 | + columns={state.columns} |
| 72 | + /> |
| 73 | + ); |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +## 4. Render your component |
| 78 | + |
| 79 | +```tsx |
| 80 | +const rootElement = document.getElementById("root"); |
| 81 | +ReactDOM.render(<App />, rootElement); |
| 82 | +``` |
| 83 | + |
| 84 | +Open example on [codesandbox.io](https://codesandbox.io/s/reactgrid-getting-started-0754c) |
| 85 | + |
| 86 | +## Docs |
| 87 | + |
| 88 | +Browse docs: [click](http://reactgrid.com/) |
| 89 | + |
| 90 | +## Licensing |
| 91 | + |
| 92 | +ReactGrid is distributed under [MIT](link) license. |
| 93 | + |
| 94 | +(c) 2020 Silevis Software |
| 95 | + |
| 96 | +## Author |
| 97 | + |
| 98 | +[Silevis Software](https://www.silevis.com/) |
| 99 | + |
| 100 | +<p align="center"> |
| 101 | + <a href="https://www.silevis.com/"> |
| 102 | + <img alt="Silevis" src="https://media.licdn.com/dms/image/C4D0BAQGgkonm5f80mA/company-logo_200_200/0?e=2159024400&v=beta&t=l5Nw-CF55OIxVORSAXOw79DlgSiDakhnYLlkBOMj7s8" width="200" /> |
| 103 | + </a> |
| 104 | +</p> |
0 commit comments