Skip to content

Commit 43d0c11

Browse files
committed
readme
1 parent ad9c01e commit 43d0c11

File tree

2 files changed

+167
-3
lines changed

2 files changed

+167
-3
lines changed

README.md

Lines changed: 165 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,165 @@
1-
# html
2-
ActiveWidgets components (no framework)
1+
2+
###
3+
4+
# ActiveWidgets/JS • Datagrid
5+
6+
[![npm version](https://img.shields.io/npm/v/@activewidgets/js)](https://www.npmjs.com/package/@activewidgets/js "View this project on npm")
7+
[![npm downloads](https://img.shields.io/npm/dm/@activewidgets/js)](https://www.npmjs.com/package/@activewidgets/js "npm package downloads/month")
8+
[![Github issues](https://img.shields.io/github/issues/activewidgets/js)](https://github.com/activewidgets/js/issues "See Github issues")
9+
[![Github repo](https://img.shields.io/github/stars/activewidgets/js?label=GitHub&style=social)](https://github.com/activewidgets/js "Open Github repo")
10+
11+
ActiveWidgets is a multi-framework UI component library. This package provides **datagrid component** for **javascript** / **no-framework** environments.
12+
13+
[Live demo](https://js.activewidgets.com) / [Developer guide](https://docs.activewidgets.com/guide/) / [API reference](https://docs.activewidgets.com/api/)
14+
15+
[![Datagrid demo](https://cdn.activewidgets.com/assets/screens/demo.png)](https://js.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/js](https://docs.activewidgets.com/api/packages/js/) to your project dependencies -
27+
28+
```sh
29+
> npm i --save @activewidgets/js
30+
```
31+
32+
## Usage
33+
34+
Import `mount` function into your app -
35+
36+
```js
37+
import { mount } from "@activewidgets/js";
38+
```
39+
40+
Now, assuming that you've added a placeholder `ax-datagrid` tag to the page
41+
42+
```html
43+
<ax-datagrid>Loading...</ax-datagrid>
44+
```
45+
46+
Mount an actual ActiveWidgets component at the placeholder position -
47+
48+
```js
49+
const rows = [
50+
{ message: 'Hello, World!' }
51+
];
52+
53+
mount('ax-datagrid', { rows });
54+
```
55+
56+
[Live example](https://js.activewidgets.com/examples/local/hello-world/) | [Source on github](https://github.com/activewidgets/js/tree/master/examples/hello-world) | [Edit on Codesandbox](https://codesandbox.io/s/github/activewidgets/js/tree/master/examples/hello-world)
57+
58+
## CDN links
59+
60+
For quick prototyping the package is also available over ActiveWidgets CDN -
61+
62+
```html
63+
<script src="https://cdn.activewidgets.com/js"></script>
64+
```
65+
66+
In this case the `mount` function is available at `ActiveWidgets.JS` global namespace.
67+
68+
```js
69+
var mount = ActiveWidgets.JS.mount;
70+
71+
var rows = [
72+
{ framework: 'none', source: 'CDN', language: 'ES5'}
73+
];
74+
75+
mount('ax-datagrid', { rows: rows });
76+
```
77+
78+
[Live example](https://js.activewidgets.com/examples/local/cdn-es5/) | [Source on github](https://github.com/activewidgets/js/tree/master/examples/cdn-es5) | [Edit on Codesandbox](https://codesandbox.io/s/github/activewidgets/js/tree/master/examples/cdn-es5)
79+
80+
## Mount function
81+
82+
The first argument for the `mount` function should be the target element (or selector).
83+
The second argument is a properties object. The target element tagName defines the component ID.
84+
85+
```js
86+
mount('#grid1', { columns, rows });
87+
```
88+
89+
The placeholder element tag must be `ax-datagrid`
90+
91+
```html
92+
<ax-datagrid id="grid1"></ax-datagrid>
93+
```
94+
95+
The mount function returns `update` and `destroy` methods.
96+
97+
98+
```js
99+
const { update } = mount('#my-grid', { columns, rows });
100+
101+
//...
102+
103+
update({ rows: newRows });
104+
105+
```
106+
107+
108+
## Data properties
109+
110+
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 -
111+
112+
- [field](https://docs.activewidgets.com/api/datagrid/columns/#field) - where the cell data comes from (string|function)
113+
- [header](https://docs.activewidgets.com/api/datagrid/columns/#header) - column header (string|object)
114+
- [width](https://docs.activewidgets.com/api/datagrid/columns/#width) - column width (number, in pixels)
115+
- [align](https://docs.activewidgets.com/api/datagrid/columns/#align) - cell text alignment (left|right|center)
116+
- [format](https://docs.activewidgets.com/api/datagrid/columns/#format) - number/date format (string|function)
117+
- [fixed](https://docs.activewidgets.com/api/datagrid/columns/#fixed) - fixed (true/false) for columns on the left or right side
118+
119+
The `style` (string|object) or `className` properties allow to change the styling of the column and cell elements.
120+
121+
```js
122+
const columns = [
123+
{ header: 'Code', field: 'customerID', width: 80, style: 'background:#def', fixed: true },
124+
{ header: 'Company Name', field: 'companyName', width: 160 },
125+
{ header: 'Contact', field: 'contactName', width: 120 },
126+
{ header: 'Title', field: 'contactTitle', width: 120 },
127+
{ header: 'Address', field: 'address', width: 120, align: 'right' }
128+
];
129+
130+
const rows = northwind.customers;
131+
132+
mount('ax-datagrid', { columns, rows });
133+
```
134+
135+
[Live example](https://js.activewidgets.com/examples/local/columns/) | [Source on github](https://github.com/activewidgets/js/tree/master/examples/columns) | [Edit on Codesandbox](https://codesandbox.io/s/github/activewidgets/js/tree/master/examples/columns)
136+
137+
138+
## User events
139+
140+
In addition to the standard DOM keyboard and mouse events the datagrid emits composite
141+
[mouse](https://docs.activewidgets.com/api/datagrid/mouse-event/) event which makes it easier to find the elements affected by the user action -
142+
143+
```js
144+
function onMouse({ row }){
145+
alert(`row ${ row.key } clicked!`);
146+
}
147+
148+
mount('ax-datagrid', { onMouse, columns, rows }); // put event handlers together with props
149+
```
150+
151+
[Live example](https://js.activewidgets.com/examples/local/events/) | [Source on github](https://github.com/activewidgets/js/tree/master/examples/events) | [Edit on Codesandbox](https://codesandbox.io/s/github/activewidgets/js/tree/master/examples/events)
152+
153+
154+
## More info
155+
156+
- [Live demo](https://react.activewidgets.com)
157+
- [Developer guide](https://docs.activewidgets.com/guide/)
158+
- [API reference](https://docs.activewidgets.com/api/)
159+
- [Licensing](https://activewidgets.com/licenses/)
160+
- [Support forum](https://activewidgets.com/messages/)
161+
162+
163+
---
164+
165+
[![ActiveWidgets](https://activewidgets.com/include/logo/aw-logo-40.png)](https://activewidgets.com)

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@
6666
"url": "git+https://github.com/activewidgets/js.git"
6767
},
6868
"keywords": [
69+
"activewidgets",
6970
"datagrid"
7071
],
7172
"bugs": {
7273
"url": "https://github.com/activewidgets/js/issues"
7374
},
74-
"homepage": "https://github.com/activewidgets/js#readme"
75+
"homepage": "https://activewidgets.com"
7576
}

0 commit comments

Comments
 (0)