|
1 |
| -# html |
2 |
| -ActiveWidgets components for jQuery |
| 1 | + |
| 2 | +### |
| 3 | + |
| 4 | +# ActiveWidgets/jQuery • Datagrid |
| 5 | + |
| 6 | +[](https://www.npmjs.com/package/@activewidgets/jquery "View this project on npm") |
| 7 | +[](https://www.npmjs.com/package/@activewidgets/jquery "npm package downloads/month") |
| 8 | +[](https://github.com/activewidgets/jquery/issues "See Github issues") |
| 9 | +[](https://github.com/activewidgets/jquery "Open Github repo") |
| 10 | + |
| 11 | +ActiveWidgets is a multi-framework UI component library. This package provides **datagrid component** for **jQuery**. |
| 12 | + |
| 13 | +[Live demo](https://jquery.activewidgets.com) / [Developer guide](https://docs.activewidgets.com/guide/) / [API reference](https://docs.activewidgets.com/api/) |
| 14 | + |
| 15 | +[](https://jquery.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/jquery](https://docs.activewidgets.com/api/packages/jquery/) to your project dependencies - |
| 27 | + |
| 28 | +```sh |
| 29 | +> npm i --save @activewidgets/jquery |
| 30 | +``` |
| 31 | + |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +Import the library into your app - |
| 36 | + |
| 37 | +```js |
| 38 | +import "@activewidgets/jquery"; |
| 39 | +``` |
| 40 | + |
| 41 | +It will add `mount` function to jQuery. Now, assuming that you've added a placeholder `ax-datagrid` tag to the page |
| 42 | + |
| 43 | +```html |
| 44 | +<ax-datagrid>Loading...</ax-datagrid> |
| 45 | +``` |
| 46 | + |
| 47 | +Assign properties and mount an actual ActiveWidgets component at the placeholder position - |
| 48 | + |
| 49 | +```js |
| 50 | +const rows = [ |
| 51 | + { message: 'Hello, World!' } |
| 52 | +]; |
| 53 | + |
| 54 | +$('ax-datagrid') |
| 55 | + .prop('rows', rows) |
| 56 | + .mount(); |
| 57 | +``` |
| 58 | + |
| 59 | +[Live example](https://jquery.activewidgets.com/examples/local/hello-world/) | [Source on github](https://github.com/activewidgets/jquery/tree/master/examples/hello-world) | [Edit on Codesandbox](https://codesandbox.io/s/github/activewidgets/jquery/tree/master/examples/hello-world) |
| 60 | + |
| 61 | + |
| 62 | +## CDN links |
| 63 | + |
| 64 | +For quick prototyping the package is also available over ActiveWidgets CDN - |
| 65 | + |
| 66 | +```html |
| 67 | +<script src="https://cdn.activewidgets.com/jquery"></script> |
| 68 | +``` |
| 69 | + |
| 70 | +[Live example](https://jquery.activewidgets.com/examples/local/cdn-es5/) | [Source on github](https://github.com/activewidgets/jquery/tree/master/examples/cdn-es5) | [Edit on Codesandbox](https://codesandbox.io/s/github/activewidgets/jquery/tree/master/examples/cdn-es5) |
| 71 | + |
| 72 | + |
| 73 | +## Mount function |
| 74 | + |
| 75 | +The `mount` function does not require any arguments - it uses element tagName as a component ID. |
| 76 | + |
| 77 | +```html |
| 78 | +<ax-datagrid id="my-grid-1"> ... </ax-datagrid> |
| 79 | +``` |
| 80 | + |
| 81 | +You can apply any selector to find the placeholder element (but the tag must be `ax-datagrid`) |
| 82 | + |
| 83 | +```js |
| 84 | +$('#my-grid-1') |
| 85 | + .prop('rows', rows) |
| 86 | + .mount(); |
| 87 | +``` |
| 88 | + |
| 89 | + |
| 90 | +## Data properties |
| 91 | + |
| 92 | +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 - |
| 93 | + |
| 94 | +- [field](https://docs.activewidgets.com/api/datagrid/columns/#field) - where the cell data comes from (string|function) |
| 95 | +- [header](https://docs.activewidgets.com/api/datagrid/columns/#header) - column header (string|object) |
| 96 | +- [width](https://docs.activewidgets.com/api/datagrid/columns/#width) - column width (number, in pixels) |
| 97 | +- [align](https://docs.activewidgets.com/api/datagrid/columns/#align) - cell text alignment (left|right|center) |
| 98 | +- [format](https://docs.activewidgets.com/api/datagrid/columns/#format) - number/date format (string|function) |
| 99 | +- [fixed](https://docs.activewidgets.com/api/datagrid/columns/#fixed) - fixed (true/false) for columns on the left or right side |
| 100 | + |
| 101 | +The `style` (string|object) or `className` properties allow to change the styling of the column and cell elements. |
| 102 | + |
| 103 | +```js |
| 104 | +const columns = [ |
| 105 | + {header: 'Code', field: 'customerID', width: 80, style: 'background:#def', fixed: true}, |
| 106 | + {header: 'Company Name', field: 'companyName', width: 160}, |
| 107 | + {header: 'Contact', field: 'contactName', width: 120}, |
| 108 | + {header: 'Title', field: 'contactTitle', width: 120}, |
| 109 | + {header: 'Address', field: 'address', width: 120, align: 'right'} |
| 110 | +]; |
| 111 | + |
| 112 | +const rows = northwind.customers; |
| 113 | + |
| 114 | +$('ax-datagrid') |
| 115 | + .prop({ columns, rows }) // use $.prop() to assign properties |
| 116 | + .mount(); |
| 117 | +``` |
| 118 | + |
| 119 | +[Live example](https://jquery.activewidgets.com/examples/local/columns/) | [Source on github](https://github.com/activewidgets/jquery/tree/master/examples/columns) | [Edit on Codesandbox](https://codesandbox.io/s/github/activewidgets/jquery/tree/master/examples/columns) |
| 120 | + |
| 121 | + |
| 122 | +## User events |
| 123 | + |
| 124 | +In addition to the standard DOM keyboard and mouse events the datagrid emits composite |
| 125 | +[mouse](https://docs.activewidgets.com/api/datagrid/mouse-event/) event which makes it easier to find the elements affected by the user action. |
| 126 | + |
| 127 | +```js |
| 128 | +function onMouse({row}){ |
| 129 | + alert(`row ${row.key} clicked!`); |
| 130 | +} |
| 131 | + |
| 132 | +$('ax-datagrid') |
| 133 | + .prop({ columns, rows }) |
| 134 | + .on('mouse', event => onMouse(event.detail)) // pass event.detail to your handler |
| 135 | + .mount(); |
| 136 | +``` |
| 137 | + |
| 138 | +[Live example](https://jquery.activewidgets.com/examples/local/events/) | [Source on github](https://github.com/activewidgets/jquery/tree/master/examples/events) | [Edit on Codesandbox](https://codesandbox.io/s/github/activewidgets/jquery/tree/master/examples/events) |
| 139 | + |
| 140 | +When assigning an event handler, note that the event data is passed in the `event.detail` property (we are using DOM CustomEvent class). |
| 141 | + |
| 142 | +ActiveWidgets custom events do not bubble, so you should always add an event handler at the component itself, not at some parent element. |
| 143 | + |
| 144 | + |
| 145 | +## More info |
| 146 | + |
| 147 | +- [Live demo](https://react.activewidgets.com) |
| 148 | +- [Developer guide](https://docs.activewidgets.com/guide/) |
| 149 | +- [API reference](https://docs.activewidgets.com/api/) |
| 150 | +- [Licensing](https://activewidgets.com/licenses/) |
| 151 | +- [Support forum](https://activewidgets.com/messages/) |
| 152 | + |
| 153 | + |
| 154 | +--- |
| 155 | + |
| 156 | +[](https://activewidgets.com) |
| 157 | + |
| 158 | + |
0 commit comments