|
| 1 | +# vue-data-table |
| 2 | + |
| 3 | +A high-customizable data-table based on [vue-clusterize](https://github.com/vue-comps/vue-clusterize) |
| 4 | + |
| 5 | +Has invisible pagination with dynamic data, pinned columns and template based header / cells. |
| 6 | + |
| 7 | +### [Demo](https://vue-comps.github.io/vue-data-table/) |
| 8 | + |
| 9 | +# Disclaimer |
| 10 | + |
| 11 | +Only for [**webpack**](https://webpack.github.io/) workflows. |
| 12 | + |
| 13 | +**No jQuery dependency** |
| 14 | + |
| 15 | +# Install |
| 16 | + |
| 17 | +```sh |
| 18 | +npm install --save-dev vue-data-table |
| 19 | +``` |
| 20 | +"data-table": require "../src/data-table.vue" |
| 21 | +"data-table-column": require "../src/data-table-column.vue" |
| 22 | +## Usage |
| 23 | +```coffee |
| 24 | +# link the components up |
| 25 | +components: |
| 26 | + "data-table": require "vue-data-table/data-table" |
| 27 | + "data-table-column": require "vue-data-table/data-table-column" |
| 28 | +# or ES6 |
| 29 | +import {dataTable,dataTableColumn} from "vue-data-table" |
| 30 | +components: { |
| 31 | + "data-table": dataTable |
| 32 | + "data-table-column": dataTableColumn |
| 33 | +} |
| 34 | +``` |
| 35 | +```html |
| 36 | +<data-table :height="200" :data="dataSet"> |
| 37 | + <data-table-column name="name" :width=80 pinned> |
| 38 | + {{data.first + " " + data.last}} |
| 39 | + <span slot="header"> Name (first + last)</span> |
| 40 | + </data-table-column> |
| 41 | +</data-table> |
| 42 | +``` |
| 43 | +For examples see [`dev/`](https://github.com/vue-comps/vue-data-table/tree/master/dev). |
| 44 | + |
| 45 | +#### Props |
| 46 | +##### data-table |
| 47 | +| Name | type | default | description | |
| 48 | +| ---:| --- | ---| --- | |
| 49 | +| binding-name | String | "data" | name to access the data in your template | |
| 50 | +| height | Number | null | Height of the clusterize element | |
| 51 | +| auto-height | Boolean | false | If autoheight should be used (see below) | |
| 52 | +| manual-start | Boolean | false | rendering doesn't start on `ready` (call `start` on the component instance instead)| |
| 53 | +| data | Array | [] | static data to render | |
| 54 | +| scrollTop | Number | 0 | sets scrollTop | |
| 55 | +| scrollLeft | Number | 0 | sets scrollLeft | |
| 56 | + |
| 57 | +##### data-table-column |
| 58 | +| Name | type | default | description | |
| 59 | +| ---:| --- | ---| --- | |
| 60 | +| name | String | - | (required) name of the column. Used as default for the header. Must be unique | |
| 61 | +| style | Object | {whiteSpace:"nowrap"} | style for the header of the column. | |
| 62 | +| pinned | Boolean | false | column will be on the left, always visible | |
| 63 | +| noResize | Boolean | false | disable resize of this column | |
| 64 | +| width | Number | -1 | initial width of the column (defaults to width of the header) | |
| 65 | +| minWidth | Number | -1 | minimal width of the column (defaults to width of the header) | |
| 66 | +| maxWidth | Number | Number.MAX_VALUE | maximal width of the column | |
| 67 | +| defaultWidth | Number or String | "auto" | width of the column on double click on resizer. "auto" looks for content width of the column | |
| 68 | + |
| 69 | +## Autoheight |
| 70 | + |
| 71 | +There are two ways data-table can be used, either use a fixed height: |
| 72 | +```html |
| 73 | +<data-table :data="dataSet" :height="400"> |
| 74 | +``` |
| 75 | + |
| 76 | +Or use autoheight: |
| 77 | +```html |
| 78 | +<html style="height:100%"> |
| 79 | + <body style="height:100%"> |
| 80 | + <div style="position:relative"> |
| 81 | + <data-table :data="dataSet" auto-height> |
| 82 | +``` |
| 83 | +In this case data-table will always fill the nearest parent element with either `position:relative;` or `position:absolute;` |
| 84 | +Keep in mind, that `padding` of the parent will be ignored. If you need a padding, use a wrapper `<div>`. |
| 85 | + |
| 86 | +## Dynamic data |
| 87 | + |
| 88 | +The data-table instance emits to events to get dynamic data: |
| 89 | +```html |
| 90 | +<data-table @get-data="getData" @get-data-count="getDataCount"> |
| 91 | +``` |
| 92 | +```js |
| 93 | +methods: |
| 94 | + # For the first datapiece, first and last will be 0 |
| 95 | + getData: function(first,last,cb) { |
| 96 | + # somehow get data |
| 97 | + cb(data) |
| 98 | + } |
| 99 | + getDataCount: function(cb) { |
| 100 | + cb(dataCount) |
| 101 | + } |
| 102 | +``` |
| 103 | +# Development |
| 104 | +Clone repository. |
| 105 | +```sh |
| 106 | +npm install |
| 107 | +npm run test |
| 108 | +``` |
| 109 | +Browse to `http://localhost:8080/`. |
| 110 | + |
| 111 | +## To-Do |
| 112 | +- allow more than one (fixed-width) object per row + autosize to adjust #objects to actual width. |
| 113 | +- use html5 history mode or document.store to save scroll position |
| 114 | + |
| 115 | +## License |
| 116 | +Copyright (c) 2016 Paul Pflugradt |
| 117 | +Licensed under the MIT license. |
0 commit comments