|
1 | 1 |
|
2 | | -[](http://www.activewidgets.com/) |
| 2 | +### |
3 | 3 |
|
4 | | -## Fast datagrid component for React |
| 4 | +# ActiveWidgets/React • Datagrid |
5 | 5 |
|
6 | | -ActiveWidgets 3.0 datagrid, implemented as React Component. |
| 6 | +[](https://www.npmjs.com/package/@activewidgets/react "View this project on npm") |
| 7 | +[](https://www.npmjs.com/package/@activewidgets/react "npm package downloads/month") |
| 8 | +[](https://github.com/activewidgets/react/issues "See Github issues") |
| 9 | +[](https://github.com/activewidgets/react "Open Github repo") |
7 | 10 |
|
8 | | -- [Examples](https://rs.activewidgets.com/) |
9 | | -- [Docs](https://rd.activewidgets.com/) |
| 11 | +ActiveWidgets is a multi-framework UI component library. This package provides **datagrid component** for **React**. |
10 | 12 |
|
11 | | -### Installation |
| 13 | +[Live demo](https://react.activewidgets.com) / [Developer guide](https://docs.activewidgets.com/guide/) / [API reference](https://docs.activewidgets.com/api/) |
12 | 14 |
|
13 | | -```bash |
14 | | -npm install @activewidgets/react |
| 15 | +[](https://react.activewidgets.com) |
| 16 | + |
| 17 | +- [Installation](#installation) |
| 18 | +- [Usage](#usage) |
| 19 | +- [CDN links](#cdn-links) |
| 20 | +- [Data properties](#data-properties) |
| 21 | +- [User events](#user-events) |
| 22 | + |
| 23 | +## Installation |
| 24 | + |
| 25 | +Add [@activewidgets/react](https://docs.activewidgets.com/api/packages/react/) to your project dependencies - |
| 26 | + |
| 27 | +```sh |
| 28 | +> npm i --save @activewidgets/react |
| 29 | +``` |
| 30 | + |
| 31 | +## Usage |
| 32 | + |
| 33 | +Now you can import ActiveWidgets component classes - |
| 34 | + |
| 35 | +```js |
| 36 | +import { Datagrid } from "@activewidgets/react"; |
| 37 | +``` |
| 38 | + |
| 39 | +and use them as any standard React component. |
| 40 | + |
| 41 | +```js |
| 42 | +import React from "react"; |
| 43 | +import ReactDOM from "react-dom"; |
| 44 | +import { Datagrid } from "@activewidgets/react"; |
| 45 | + |
| 46 | +const rows = [ |
| 47 | + { message: 'Hello, World!' } |
| 48 | +]; |
| 49 | + |
| 50 | +function App(){ |
| 51 | + return <Datagrid rows={rows} /> |
| 52 | +} |
| 53 | + |
| 54 | +ReactDOM.render(<App />, document.getElementById("app")); |
| 55 | +``` |
| 56 | + |
| 57 | +[Live example](https://react.activewidgets.com/examples/local/hello-world/) | [Source on github](https://github.com/activewidgets/react/tree/master/examples/hello-world) | [Edit on Codesandbox](https://codesandbox.io/s/github/activewidgets/react/tree/master/examples/hello-world) |
| 58 | + |
| 59 | +## CDN links |
| 60 | + |
| 61 | +For quick prototyping the package is also available over ActiveWidgets CDN - |
| 62 | + |
| 63 | +```html |
| 64 | +<script src="https://cdn.activewidgets.com/react"></script> |
| 65 | +``` |
| 66 | + |
| 67 | +In this case you will find the components at `ActiveWidgets.React` global namespace. |
| 68 | + |
| 69 | +```js |
| 70 | +var Datagrid = ActiveWidgets.React.Datagrid; |
| 71 | + |
| 72 | +var rows = [ |
| 73 | + { framework: 'React', source: 'CDN', language: 'ES5' } |
| 74 | +]; |
| 75 | + |
| 76 | +var App = React.createElement(Datagrid, { rows: rows }); |
| 77 | +ReactDOM.render(App, document.getElementById("app")); |
15 | 78 | ``` |
16 | 79 |
|
17 | | -### Usage |
| 80 | +[Live example](https://react.activewidgets.com/examples/local/cdn-es5/) | [Source on github](https://github.com/activewidgets/react/tree/master/examples/cdn-es5) | [Edit on Codesandbox](https://codesandbox.io/s/github/activewidgets/react/tree/master/examples/cdn-es5) |
| 81 | + |
| 82 | +## Data properties |
| 83 | + |
| 84 | +You have to provide [columns](https://docs.activewidgets.com/api/datagrid/columns/) and [rows](https://docs.activewidgets.com/api/datagrid/rows/) properties to the datagrid to show some data. The properties of each `column` object define how the data will be rendered - |
| 85 | + |
| 86 | +- [field](https://docs.activewidgets.com/api/datagrid/columns/#field) - where the cell data comes from (string|function) |
| 87 | +- [header](https://docs.activewidgets.com/api/datagrid/columns/#header) - column header (string|object) |
| 88 | +- [width](https://docs.activewidgets.com/api/datagrid/columns/#width) - column width (number, in pixels) |
| 89 | +- [align](https://docs.activewidgets.com/api/datagrid/columns/#align) - cell text alignment (left|right|center) |
| 90 | +- [format](https://docs.activewidgets.com/api/datagrid/columns/#format) - number/date format (string|function) |
| 91 | +- [fixed](https://docs.activewidgets.com/api/datagrid/columns/#fixed) - fixed (true/false) for columns on the left or right side |
| 92 | + |
| 93 | +The `style` (string|object) or `className` properties allow to change the styling of the column and cell elements. |
18 | 94 |
|
19 | 95 | ```js |
20 | | -import React from 'react'; |
21 | | -import ReactDOM from 'react-dom'; |
22 | | -import {Datagrid} from '@activewidgets/react'; |
23 | | -import {columns, rows} from './data.js'; |
| 96 | +const columns = [ |
| 97 | + {header: 'Code', field: 'customerID', width: 80, style: 'background:#def', fixed: true}, |
| 98 | + {header: 'Company Name', field: 'companyName', width: 160}, |
| 99 | + {header: 'Contact', field: 'contactName', width: 120}, |
| 100 | + {header: 'Title', field: 'contactTitle', width: 120}, |
| 101 | + {header: 'Address', field: 'address', width: 120, align: 'right'} |
| 102 | +]; |
| 103 | + |
| 104 | +const rows = northwind.customers; |
| 105 | + |
| 106 | +function App(){ |
| 107 | + return <Datagrid columns={columns} rows={rows} /> |
| 108 | +} |
| 109 | +``` |
| 110 | + |
| 111 | +[Live example](https://react.activewidgets.com/examples/local/columns/) | [Source on github](https://github.com/activewidgets/react/tree/master/examples/columns) | [Edit on Codesandbox](https://codesandbox.io/s/github/activewidgets/react/tree/master/examples/columns) |
| 112 | + |
24 | 113 |
|
25 | | -const app = <Datagrid columns={columns} rows={rows} />; |
| 114 | +## User events |
| 115 | + |
| 116 | +In addition to the standard DOM keyboard and mouse events the datagrid emits composite |
| 117 | +[mouse](https://docs.activewidgets.com/api/datagrid/mouse-event/) event which makes it easier to find the elements affected by the user action - |
| 118 | + |
| 119 | +```js |
| 120 | +function onMouse({row, column}){ |
| 121 | + alert(`row ${row.key} clicked!`); |
| 122 | +} |
26 | 123 |
|
27 | | -ReactDOM.render(app, document.getElementById('app')); |
| 124 | +function App(){ |
| 125 | + return <Datagrid onMouse={onMouse} columns={columns} rows={rows} /> |
| 126 | +} |
28 | 127 | ``` |
29 | 128 |
|
30 | | -See http://www.activewidgets.com/ |
| 129 | +[Live example](/examples/react/events/) | [Source on github](https://github.com/activewidgets/react/tree/master/examples/events) | [Edit on Codesandbox](https://codesandbox.io/s/github/activewidgets/react/tree/master/examples/events) |
| 130 | + |
| 131 | +## More info |
| 132 | + |
| 133 | +- [Live demo](https://react.activewidgets.com) |
| 134 | +- [Developer guide](https://docs.activewidgets.com/guide/) |
| 135 | +- [API reference](https://docs.activewidgets.com/api/) |
| 136 | +- [Licensing](https://activewidgets.com/licenses/) |
| 137 | +- [Support forum](https://activewidgets.com/messages/) |
| 138 | + |
| 139 | + |
| 140 | +--- |
| 141 | + |
| 142 | +[](https://activewidgets.com) |
0 commit comments