https://github.com/activewidgets/html
ActiveWidgets components for HTML (custom elements)
https://github.com/activewidgets/html
Last synced: 12 months ago
JSON representation
ActiveWidgets components for HTML (custom elements)
- Host: GitHub
- URL: https://github.com/activewidgets/html
- Owner: activewidgets
- License: mit
- Created: 2019-12-28T17:47:55.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-04-30T18:49:13.000Z (almost 3 years ago)
- Last Synced: 2025-02-15T02:05:30.572Z (12 months ago)
- Language: JavaScript
- Homepage: http://www.activewidgets.com
- Size: 1.41 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
###
# ActiveWidgets/HTML • Datagrid
[](https://www.npmjs.com/package/@activewidgets/html "View this project on npm")
[](https://www.npmjs.com/package/@activewidgets/html "npm package downloads/month")
[](https://github.com/activewidgets/html/issues "See Github issues")
[](https://github.com/activewidgets/html "Open Github repo")
ActiveWidgets is a multi-framework UI component library. This package provides **datagrid component** as **HTML5/CustomElement**.
[Live demo](https://html.activewidgets.com) / [Developer guide](https://activewidgets.com/guide/) / [API reference](https://activewidgets.com/api/)
[](https://html.activewidgets.com)
- [Installation](#installation)
- [Usage](#usage)
- [CDN links](#cdn-links)
- [Data properties](#data-properties)
- [User events](#user-events)
## Installation
Add [@activewidgets/html](https://activewidgets.com/api/packages/html/) to your project dependencies -
```sh
> npm i --save @activewidgets/html
```
## Usage
Import the library into your app to register the custom element tags -
```js
import "@activewidgets/html";
```
The `ax-...` tags will now function as ActiveWidgets components.
```html
Loading...
```
You can then assign properties and event handlers using standard DOM API.
```js
const el = document.querySelector('ax-datagrid');
el.rows = [
{ message: 'Hello, World!' }
];
```
[Live example](https://html.activewidgets.com/hello-world/) | [Source on github](https://github.com/activewidgets/html/tree/master/examples/hello-world) | [Edit on stackblitz](https://stackblitz.com/github/activewidgets/html/tree/master/examples/hello-world?file=src/index.js)
## CDN links
For quick prototyping the package is also available over ActiveWidgets CDN -
```html
```
[Live example](https://html.activewidgets.com/examples/local/cdn-es5/) | [Source on github](https://github.com/activewidgets/html/tree/master/examples/cdn-es5) | [Edit on stackblitz](https://stackblitz.com/github/activewidgets/html/tree/master/examples/cdn-es5)
## Data properties
You have to provide [columns](https://activewidgets.com/api/datagrid/columns/) and [rows](https://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 -
- [field](https://activewidgets.com/api/datagrid/columns/#field) - where the cell data comes from (string|function)
- [header](https://activewidgets.com/api/datagrid/columns/#header) - column header (string|object)
- [width](https://activewidgets.com/api/datagrid/columns/#width) - column width (number, in pixels)
- [align](https://activewidgets.com/api/datagrid/columns/#align) - cell text alignment (left|right|center)
- [format](https://activewidgets.com/api/datagrid/columns/#format) - number/date format (string|function)
- [fixed](https://activewidgets.com/api/datagrid/columns/#fixed) - fixed (true/false) for columns on the left or right side
The `style` (string|object) or `className` properties allow to change the styling of the column and cell elements.
```js
const el = document.querySelector('ax-datagrid');
el.columns = [
{ header: 'Code', field: 'customerID', width: 80, style: 'background:#def', fixed: true },
{ header: 'Company Name', field: 'companyName', width: 160 },
{ header: 'Contact', field: 'contactName', width: 120 },
{ header: 'Title', field: 'contactTitle', width: 120 },
{ header: 'Address', field: 'address', width: 120, align: 'right' }
];
el.rows = northwind.customers;
```
[Live example](https://html.activewidgets.com/columns/) | [Source on github](https://github.com/activewidgets/html/tree/master/examples/columns) | [Edit on stackblitz](https://stackblitz.com/github/activewidgets/html/tree/master/examples/columns?file=src/index.js)
## User events
In addition to the standard DOM keyboard and mouse events the datagrid emits composite
[mouse](https://activewidgets.com/api/datagrid/mouse-event/) event which makes it easier to find the elements affected by the user action.
```js
function onMouse({row}){
alert(`row ${row.key} clicked!`);
}
const el = document.querySelector('ax-datagrid');
el.columns = columns;
el.rows = rows;
el.addEventListener('mouse', event => onMouse(event.detail), true);
```
[Live example](https://html.activewidgets.com/events/) | [Source on github](https://github.com/activewidgets/html/tree/master/examples/events) | [Edit on stackblitz](https://stackblitz.com/github/activewidgets/html/tree/master/examples/events?file=src/index.js)
When assigning an event handler, note that the event data is passed in the `event.detail` property (we are using DOM CustomEvent class).
ActiveWidgets custom events do not bubble, so you should always add an event handler at the component itself, not at some parent element.
## More info
- [Live demo](https://react.activewidgets.com)
- [Developer guide](https://activewidgets.com/guide/)
- [API reference](https://activewidgets.com/api/)
- [Licensing](https://activewidgets.com/licenses/)
- [Support forum](https://activewidgets.com/messages/)
---
[](https://activewidgets.com)