|
1 | 1 |
|
2 |
| -[](http://www.activewidgets.com/) |
| 2 | +### |
3 | 3 |
|
4 |
| -## Fast datagrid component for Vue.js |
| 4 | +# ActiveWidgets/Vue • Datagrid |
5 | 5 |
|
6 |
| -ActiveWidgets 3.0 datagrid, implemented as Vue.js Component. |
| 6 | +[](https://www.npmjs.com/package/@activewidgets/vue "View this project on npm") |
| 7 | +[](https://www.npmjs.com/package/@activewidgets/vue "npm package downloads/month") |
| 8 | +[](https://github.com/activewidgets/vue/issues "See Github issues") |
| 9 | +[](https://github.com/activewidgets/vue "Open Github repo") |
7 | 10 |
|
8 |
| -- [Examples](https://vs.activewidgets.com/) |
9 |
| -- [Docs](https://vd.activewidgets.com/) |
| 11 | +ActiveWidgets is a multi-framework UI component library. This package provides **datagrid component** for **Vue**. |
10 | 12 |
|
11 |
| -### Installation |
| 13 | +[Live demo](https://vue.activewidgets.com) / [Developer guide](https://docs.activewidgets.com/guide/) / [API reference](https://docs.activewidgets.com/api/) |
12 | 14 |
|
13 |
| -```bash |
14 |
| -npm install @activewidgets/vue |
| 15 | +[](https://vue.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/vue](https://docs.activewidgets.com/api/packages/vue/) to your project dependencies - |
| 26 | + |
| 27 | +```sh |
| 28 | +> npm i --save @activewidgets/vue |
| 29 | +``` |
| 30 | + |
| 31 | +## Usage |
| 32 | + |
| 33 | +Now you can import ActiveWidgets component classes - |
| 34 | + |
| 35 | +```js |
| 36 | +import { components } from "@activewidgets/vue"; |
15 | 37 | ```
|
16 | 38 |
|
17 |
| -### Usage |
| 39 | +and register them with Vue. |
18 | 40 |
|
19 | 41 | ```js
|
20 |
| -import Vue from 'vue'; |
21 | 42 | import {components} from '@activewidgets/vue';
|
22 |
| -import {columns, rows} from './data.js'; |
23 | 43 |
|
24 |
| -const data = {columns, rows}; |
| 44 | +// ... |
| 45 | + |
| 46 | +export default { components, data }; |
| 47 | +``` |
| 48 | + |
| 49 | +It makes `ax-datagrid` and other `ax-...` tags available in your component template - |
25 | 50 |
|
26 |
| -new Vue({ |
27 |
| - el: '#app', |
28 |
| - template: '<ax-datagrid :rows="rows" :columns="columns"></ax-datagrid>', |
29 |
| - components: components, |
30 |
| - data: data |
31 |
| -}); |
| 51 | +```html |
| 52 | +<template> |
| 53 | + <ax-datagrid :rows="rows"></ax-datagrid> |
| 54 | +</template> |
32 | 55 | ```
|
| 56 | +[Live example](https://vue.activewidgets.com/examples/local/hello-world/) | [Source on github](https://github.com/activewidgets/vue/tree/master/examples/hello-world) | [Edit on Codesandbox](https://codesandbox.io/s/github/activewidgets/vue/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/vue"></script> |
| 64 | +``` |
| 65 | + |
| 66 | +In this case you will find the components at `ActiveWidgets.Vue` global namespace. |
| 67 | + |
| 68 | +```js |
| 69 | +var components = ActiveWidgets.Vue.components; |
| 70 | + |
| 71 | +// or |
| 72 | + |
| 73 | +var Datagrid = ActiveWidgets.Vue.Datagrid; |
| 74 | +``` |
| 75 | + |
| 76 | +## Data properties |
| 77 | + |
| 78 | +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 - |
| 79 | + |
| 80 | +- [field](https://docs.activewidgets.com/api/datagrid/columns/#field) - where the cell data comes from (string|function) |
| 81 | +- [header](https://docs.activewidgets.com/api/datagrid/columns/#header) - column header (string|object) |
| 82 | +- [width](https://docs.activewidgets.com/api/datagrid/columns/#width) - column width (number, in pixels) |
| 83 | +- [align](https://docs.activewidgets.com/api/datagrid/columns/#align) - cell text alignment (left|right|center) |
| 84 | +- [format](https://docs.activewidgets.com/api/datagrid/columns/#format) - number/date format (string|function) |
| 85 | +- [fixed](https://docs.activewidgets.com/api/datagrid/columns/#fixed) - fixed (true/false) for columns on the left or right side |
| 86 | + |
| 87 | +The `style` (string|object) or `className` properties allow to change the styling of the column and cell elements. |
| 88 | + |
| 89 | +```js |
| 90 | +function data(){ |
| 91 | + |
| 92 | + const columns = [ |
| 93 | + {header: 'Code', field: 'customerID', style: 'background:#def', fixed: true}, |
| 94 | + {header: 'Company Name', field: 'companyName', width: 160}, |
| 95 | + {header: 'Contact', field: 'contactName', width: 120}, |
| 96 | + {header: 'Title', field: 'contactTitle', width: 120}, |
| 97 | + {header: 'Address', field: 'address', width: 120, align: right} |
| 98 | + ]; |
| 99 | + |
| 100 | + const rows = northwind.customers; |
| 101 | + |
| 102 | + return { columns, rows }; |
| 103 | +} |
| 104 | +``` |
| 105 | + |
| 106 | +```html |
| 107 | +<template> |
| 108 | + <ax-datagrid :columns="columns" :rows="rows"></ax-datagrid> |
| 109 | +</template> |
| 110 | +``` |
| 111 | +[Live example](https://vue.activewidgets.com/examples/local/columns/) | [Source on github](https://github.com/activewidgets/vue/tree/master/examples/columns) | [Edit on Codesandbox](https://codesandbox.io/s/github/activewidgets/vue/tree/master/examples/columns) |
| 112 | + |
| 113 | + |
| 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}){ |
| 121 | + alert(`row ${row.key} clicked!`); |
| 122 | +} |
| 123 | + |
| 124 | +const methods = { onMouse }; |
| 125 | +export default { components, data, methods }; |
| 126 | +``` |
| 127 | + |
| 128 | +```html |
| 129 | +<template> |
| 130 | + <ax-datagrid @mouse="onMouse" :columns="columns" :rows="rows"></ax-datagrid> |
| 131 | +</template> |
| 132 | +``` |
| 133 | +[Live example](https://vue.activewidgets.com/examples/local/events/) | [Source on github](https://github.com/activewidgets/vue/tree/master/examples/events) | [Edit on Codesandbox](https://codesandbox.io/s/github/activewidgets/vue/tree/master/examples/events) |
| 134 | + |
| 135 | +## More info |
| 136 | + |
| 137 | +- [Live demo](https://react.activewidgets.com) |
| 138 | +- [Developer guide](https://docs.activewidgets.com/guide/) |
| 139 | +- [API reference](https://docs.activewidgets.com/api/) |
| 140 | +- [Licensing](https://activewidgets.com/licenses/) |
| 141 | +- [Support forum](https://activewidgets.com/messages/) |
| 142 | + |
| 143 | + |
| 144 | +--- |
33 | 145 |
|
34 |
| -See http://www.activewidgets.com/ |
| 146 | +[](https://activewidgets.com) |
0 commit comments