|
1 | 1 | # Vue Datasource
|
2 |
| -#### A Vue.js component to create tables from Server Side. Compatible with Vue 2.x and Laravel |
| 2 | +#### A Vue.js server side component to create tables. Compatible with Vue 2.x and Laravel |
3 | 3 |
|
4 | 4 | ### Demo
|
5 | 5 |
|
6 | 6 | Temporal: http://recordit.co/F9c92b277R
|
7 | 7 |
|
8 |
| -Coming soon live demo ... |
| 8 | +Live demo coming soon .... |
9 | 9 |
|
10 | 10 | ### Install/Usage
|
11 | 11 | ```
|
@@ -53,43 +53,117 @@ new Vue({
|
53 | 53 | ### Available Props
|
54 | 54 | | Prop | Type | Default | Description |
|
55 | 55 | |-------------|---------|---------|-------------------------------------------------------------|
|
56 |
| -| tableData | Array | | The table information to display | |
57 |
| -| language | String | es | Defines the language with which the table will be displayed | |
58 |
| -| columns | Array | | Columns to display in table | |
59 |
| -| pagination | Object | | Information about data collection to paginate | |
60 |
| -| actions | Array | | Buttons to perform action on click event | |
| 56 | +| table-data | Array | | Table information | |
| 57 | +| language | String | es | Defines the table labels language | |
| 58 | +| columns | Array | | Columns to display | |
| 59 | +| pagination | Object | | Pagination information about the table data ([structure] (#pagination-structure)) | |
| 60 | +| actions | Array | | Action buttons ([structure] (#action-event-sctructure)) | |
61 | 61 |
|
62 | 62 | ### Available Events
|
63 |
| -| Event | Description | |
64 |
| -|-------------|------------------------------------------------| |
65 |
| -| change | Return the limit per page and the current page | |
66 |
| -| searching | Return the string to search | |
| 63 | +| Event | Description | |
| 64 | +|-------------|-----------------------------------------------------------------------------------------------------| |
| 65 | +| change | Handle show limit changed. Gets object with new show limit and current page `{perpage: 10, page: 2}`| |
| 66 | +| searching | Handles search input. Gets string as parameter | |
67 | 67 |
|
68 |
| -### Render column value with custom format |
69 |
| -To show the value of a column with a custom format uses the render property, this will allow you to get the original value and return it in the way you define. |
| 68 | +### Columns |
| 69 | +Each column object needs a `name` and `key` attributes. |
70 | 70 | ```javascript
|
71 | 71 | {
|
72 | 72 | ...,
|
73 | 73 | columns: [
|
74 | 74 | {
|
75 |
| - name: 'Name', // Header name column |
76 |
| - // Name of column on table. If you are working in Laravel |
77 |
| - // you can access the relationships using 'relation.key' |
78 |
| - key: 'name', |
79 |
| - render(value) { |
| 75 | + name: 'Name', // Table column name to display |
| 76 | + key: 'name', // Key name from row object |
| 77 | + } |
| 78 | + ] |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +For Laravel users, you can access relationships through the `key` attribute. Lets say we have the following object in our users array. |
| 83 | + |
| 84 | +```javascript |
| 85 | +[ |
| 86 | + ..., |
| 87 | + { |
| 88 | + name: 'Foo', |
| 89 | + last_name: 'Bar' |
| 90 | + role_id: 1, |
| 91 | + role: { |
| 92 | + name: 'admin' |
| 93 | + } |
| 94 | + } |
| 95 | +] |
| 96 | +``` |
| 97 | + |
| 98 | +To get the user's role we would need to define in our columns array: |
| 99 | +```javascript |
| 100 | +{ |
| 101 | + ..., |
| 102 | + columns: [ |
| 103 | + { |
| 104 | + name: 'Role', |
| 105 | + key: 'role.name' |
| 106 | + } |
| 107 | + ] |
| 108 | +} |
| 109 | +``` |
| 110 | + |
| 111 | + |
| 112 | +### Render column |
| 113 | +This callback will modify the data for various operations. Such as applying a specific format or an arithmetic operation to the column value and return it. |
| 114 | +```javascript |
| 115 | +{ |
| 116 | + ..., |
| 117 | + columns: [ |
| 118 | + { |
| 119 | + name: 'Name', |
| 120 | + key: 'name', |
| 121 | + render(value) { // Render callback |
80 | 122 | return `Enginner ${value}`;
|
81 | 123 | }
|
82 | 124 | }
|
83 | 125 | ]
|
84 | 126 | }
|
85 | 127 | ```
|
86 | 128 |
|
| 129 | +### Pagination Structure |
| 130 | +```javascript |
| 131 | +{ |
| 132 | + ..., |
| 133 | + pagination: { |
| 134 | + total: 25, // Number of total rows (default 0) |
| 135 | + per_page: 15, // Number of rows to show (default 15) |
| 136 | + current_page: 1, // Actual page |
| 137 | + last_page: 2, // Last page |
| 138 | + from: 1, // Beginning of visible rows |
| 139 | + to: 15 // End of visible rows |
| 140 | + } |
| 141 | +} |
| 142 | +``` |
| 143 | + |
| 144 | +### Action Event Sctructure |
| 145 | +```javascript |
| 146 | +{ |
| 147 | + ..., |
| 148 | + actions: [ |
| 149 | + { |
| 150 | + text: 'Click me', // Button label |
| 151 | + icon: 'glyphicon glyphicon-check', // Button icon |
| 152 | + class: 'btn-primary', // Button class (background color) |
| 153 | + event(e, row) { // Event handler callback. Gets event instace and selected row |
| 154 | + console.log('Click row: ', row); // If no row is selected, row will be NULL |
| 155 | + } |
| 156 | + } |
| 157 | + ] |
| 158 | +} |
| 159 | +``` |
| 160 | + |
87 | 161 | ### Implementation examples
|
88 | 162 | - Using Laravel 5.3 and pagination: [laravel-datasource-example](https://github.com/coderdiaz/laravel-datasource-example).
|
89 | 163 |
|
90 |
| -_You can add implementations send me your PR._ |
91 | 164 |
|
92 | 165 | ### Contributions
|
93 | 166 | All contributions are welcome send your PR and Issues.
|
94 | 167 |
|
95 |
| -#### Created by Javier Diaz |
| 168 | +##### Created by Javier Diaz. Translation enhancement by [itsuwaribito] (https://github.com/itsuwaribito) |
| 169 | + |
0 commit comments