Skip to content

Commit 4654bba

Browse files
committed
readme
1 parent b68c775 commit 4654bba

3 files changed

Lines changed: 142 additions & 9 deletions

File tree

README.md

Lines changed: 136 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,144 @@
11

2-
[![ActiveWidgets](http://www.activewidgets.com/include/logo/aw-logo-40.png?activewidgets/react)](http://www.activewidgets.com/)
2+
###
33

4-
## Fast datagrid component for preact
4+
# ActiveWidgets/Preact • Datagrid
55

6-
ActiveWidgets 3.0 datagrid, implemented as preact Component.
6+
[![npm version](https://img.shields.io/npm/v/@activewidgets/preact)](https://www.npmjs.com/package/@activewidgets/preact "View this project on npm")
7+
[![npm downloads](https://img.shields.io/npm/dm/@activewidgets/preact)](https://www.npmjs.com/package/@activewidgets/preact "npm package downloads/month")
8+
[![Github issues](https://img.shields.io/github/issues/activewidgets/preact)](https://github.com/activewidgets/preact/issues "See Github issues")
9+
[![Github repo](https://img.shields.io/github/stars/activewidgets/preact?label=GitHub&style=social)](https://github.com/activewidgets/preact "Open Github repo")
710

11+
ActiveWidgets is a multi-framework UI component library. This package provides **datagrid component** for **Preact**.
812

9-
### Installation
13+
[Live demo](https://preact.activewidgets.com) / [Developer guide](https://docs.activewidgets.com/guide/) / [API reference](https://docs.activewidgets.com/api/)
1014

11-
```bash
12-
npm install @activewidgets/preact
15+
[![Datagrid demo](https://cdn.activewidgets.com/assets/screens/demo.png)](https://preact.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+
24+
## Installation
25+
26+
Add [@activewidgets/preact](https://docs.activewidgets.com/api/packages/preact/) to your project dependencies -
27+
28+
```sh
29+
> npm i --save @activewidgets/preact
30+
```
31+
32+
## Usage
33+
34+
Now you can import ActiveWidgets component classes -
35+
36+
```js
37+
import { Datagrid } from "@activewidgets/preact";
38+
```
39+
40+
and use them as any standard Preact component.
41+
42+
```js
43+
import { h, render } from 'preact';
44+
import { Datagrid } from '@activewidgets/preact';
45+
import './styles.css';
46+
47+
const rows = [
48+
{ message: 'Hello, World!' }
49+
];
50+
51+
function App(){
52+
return <Datagrid rows={rows} />
53+
}
54+
55+
render(<App />, document.getElementById('app'));
56+
```
57+
58+
[Live example](https://preact.activewidgets.com/examples/local/hello-world/) | [Source on github](https://github.com/activewidgets/preact/tree/master/examples/hello-world) | [Edit on Codesandbox](https://codesandbox.io/s/github/activewidgets/preact/tree/master/examples/hello-world)
59+
60+
## CDN links
61+
62+
For quick prototyping the package is also available over ActiveWidgets CDN -
63+
64+
```html
65+
<script src="https://cdn.activewidgets.com/preact"></script>
1366
```
1467

15-
See http://www.activewidgets.com/
68+
In this case you will find the components at `ActiveWidgets.Preact` global namespace.
69+
70+
```js
71+
var Datagrid = ActiveWidgets.Preact.Datagrid;
72+
73+
var rows = [
74+
{ framework: 'preact', source: 'CDN', language: 'ES5'}
75+
];
76+
77+
var App = preact.h(Datagrid, {rows: rows});
78+
preact.render(App, document.getElementById("app"));
79+
```
80+
81+
[Live example](https://preact.activewidgets.com/examples/local/cdn-es5/) | [Source on github](https://github.com/activewidgets/preact/tree/master/examples/cdn-es5) | [Edit on Codesandbox](https://codesandbox.io/s/github/activewidgets/preact/tree/master/examples/cdn-es5)
82+
83+
## Data properties
84+
85+
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 -
86+
87+
- [field](https://docs.activewidgets.com/api/datagrid/columns/#field) - where the cell data comes from (string|function)
88+
- [header](https://docs.activewidgets.com/api/datagrid/columns/#header) - column header (string|object)
89+
- [width](https://docs.activewidgets.com/api/datagrid/columns/#width) - column width (number, in pixels)
90+
- [align](https://docs.activewidgets.com/api/datagrid/columns/#align) - cell text alignment (left|right|center)
91+
- [format](https://docs.activewidgets.com/api/datagrid/columns/#format) - number/date format (string|function)
92+
- [fixed](https://docs.activewidgets.com/api/datagrid/columns/#fixed) - fixed (true/false) for columns on the left or right side
93+
94+
The `style` (string|object) or `className` properties allow to change the styling of the column and cell elements.
95+
96+
```js
97+
const columns = [
98+
{header: 'Code', field: 'customerID', width: 80, style: 'background:#def', fixed: true},
99+
{header: 'Company Name', field: 'companyName', width: 160},
100+
{header: 'Contact', field: 'contactName', width: 120},
101+
{header: 'Title', field: 'contactTitle', width: 120},
102+
{header: 'Address', field: 'address', width: 120, align: 'right'}
103+
];
104+
105+
const rows = northwind.customers;
106+
107+
function App(){
108+
return <Datagrid columns={columns} rows={rows} />
109+
}
110+
```
111+
112+
[Live example](https://preact.activewidgets.com/examples/local/columns/) | [Source on github](https://github.com/activewidgets/preact/tree/master/examples/columns) | [Edit on Codesandbox](https://codesandbox.io/s/github/activewidgets/preact/tree/master/examples/columns)
113+
114+
115+
## User events
116+
117+
In addition to the standard DOM keyboard and mouse events the datagrid emits composite
118+
[mouse](https://docs.activewidgets.com/api/datagrid/mouse-event/) event which makes it easier to find the elements affected by the user action -
119+
120+
```js
121+
function onMouse({row, column}){
122+
alert(`row ${row.key} clicked!`);
123+
}
124+
125+
function App(){
126+
return <Datagrid onMouse={onMouse} columns={columns} rows={rows} />
127+
}
128+
```
129+
130+
[Live example](https://preact.activewidgets.com/examples/local/events/) | [Source on github](https://github.com/activewidgets/preact/tree/master/examples/events) | [Edit on Codesandbox](https://codesandbox.io/s/github/activewidgets/preact/tree/master/examples/events)
131+
132+
133+
## More info
134+
135+
- [Live demo](https://react.activewidgets.com)
136+
- [Developer guide](https://docs.activewidgets.com/guide/)
137+
- [API reference](https://docs.activewidgets.com/api/)
138+
- [Licensing](https://activewidgets.com/licenses/)
139+
- [Support forum](https://activewidgets.com/messages/)
140+
141+
142+
---
143+
144+
[![ActiveWidgets](https://activewidgets.com/include/logo/aw-logo-40.png)](https://activewidgets.com)

examples/columns/src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ const columns = [
2323
{header: 'Country', field: 'country'}
2424
];
2525

26+
const rows = northwind.customers;
27+
2628

2729
function App(){
28-
return <Datagrid columns={columns} rows={northwind.customers} />
30+
return <Datagrid columns={columns} rows={rows} />
2931
}
3032

3133

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@
6868
"url": "git+https://github.com/activewidgets/preact.git"
6969
},
7070
"keywords": [
71+
"activewidgets",
72+
"datagrid",
7173
"react"
7274
],
7375
"bugs": {
7476
"url": "https://github.com/activewidgets/preact/issues"
7577
},
76-
"homepage": "https://github.com/activewidgets/preact#readme"
78+
"homepage": "https://activewidgets.com"
7779
}

0 commit comments

Comments
 (0)