You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+44-18Lines changed: 44 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,9 +31,9 @@ npm install vue-datatables-net
31
31
```
32
32
33
33
## Usage
34
-
This library default configuration and provide example for use with `bootstrap4` styling. Though, you can fully customize with any other jQuery DataTables supported theme.
34
+
This library default configuration and provide example for use with `bootstrap4` styling. Though, it allow for complete flexibility of customization with any other jQuery DataTables supported theme.
> See example [App](https://niiknow.github.io/vue-datatables-net/)
76
76
77
-
Example App demonstrate how to pass in overrides for our [jQuery DataTable](https://datatables.net/manual/options) default options - https://github.com/niiknow/vue-datatables-net/blob/master/example/App.vue#L8
77
+
Example App demonstrate how to pass in overrides for our [jQuery DataTable](https://datatables.net/manual/options) default options - https://github.com/niiknow/vue-datatables-net/blob/master/example/App.vue
78
78
79
79
**NOTE:**
80
80
Our example use a free API endpoint from [typicode](https://jsonplaceholder.typicode.com), which is simply a JSON endpoint. As a result, we needed to define a `dataSrc` wrapper like so:
@@ -87,7 +87,7 @@ ajax: {
87
87
}
88
88
```
89
89
90
-
Here are some jQuery DataTables server-side compatible parsers:
90
+
Of course, for your implementation, simply use a server-side compatible parser. Below are some jQuery DataTables server-side parsers:
* Current implementation require datatables.net-select
143
143
*
144
-
* @typeBoolean
144
+
* @typeNumber
145
145
*/
146
-
selectable: {
147
-
type:Boolean
148
-
}
146
+
selectCheckbox: {
147
+
type:Number
148
+
},
149
149
/**
150
150
* Provide custom local data loading. Warning: this option has not been
151
151
* thoroughly tested. Please use ajax and serverSide instead.
@@ -162,6 +162,14 @@ Our component parameters:
162
162
*/
163
163
hideFooter: {
164
164
type:Boolean
165
+
},
166
+
/**
167
+
* The details column configuration of master/details.
168
+
*
169
+
* @type{Object}
170
+
*/
171
+
details: {
172
+
type:Object
165
173
}
166
174
}
167
175
```
@@ -187,18 +195,18 @@ fields: {
187
195
-`className` set column class names
188
196
-`defaultContent` provide default html when no data available
189
197
-`render` custom cell rendering function https://datatables.net/reference/option/columns.render
190
-
-`template` simple vue template for the field
198
+
-`template` simple vue template for the field. See example App.
191
199
192
-
> It is important to understand why one should use `fields` and not simply pass in `opts.columns`. Though, `fields`definition is optional, you can just pass `opts.columns` definition if you do not wish to use `fields`.
200
+
> It is important to understand why one should use `fields` and not `opts.columns`. Though, `fields` is optional, you can simply pass `opts.columns` definition if you do not wish to use `fields`.
193
201
194
202
One `Purpose` of this component is to extend jQuery DataTables function and features, example:
195
203
* Simplification of features configuration, such as `select-checkbox` column, custom `action` buttons, and/or future Vue specific features.
196
-
* Allow for customizable table heading on a percolumn basis; thereby, not having to define all html for column header.
197
-
* Ability to have simple `template` field so you can pass schema JSON from static file or some API instead of requiring to define a javascript `render` function. Though, the `render` function would provide best performance.
204
+
* Allow for customizable table heading on a per-column basis; thereby, not having to define all html for each column header.
205
+
* Ability to have simple `template` field so you can pass schema JSON from static file or some API, instead of requiring to define a javascript `render` function. Though, the `render` function would provide best performance.
198
206
* Having schema also allow future features, such as: support of editable column/cell.
199
207
200
208
## Additional Headers
201
-
Many server-side usage require CSRF and/or API token headers. Since options are completely exposed, simply use the native method per [jQuery DataTables example](https://editor.datatables.net/manual/security#Prevention)
209
+
Many server-side usage require CSRF and/or API token headers. Since jQuery DataTables `options` are completely exposed as `opts`, simply use the native method per [jQuery DataTables example](https://editor.datatables.net/manual/security#Prevention)
202
210
203
211
i.e, something like:
204
212
```javascript
@@ -236,7 +244,7 @@ opts: {
236
244
237
245
```
238
246
239
-
If you haven't already figured it out, ajax is basically the signature of [jQuery.ajax](http://api.jquery.com/jquery.ajax/) which is demonstrated here wrapped as[jQuery DataTables ajax pipeline](https://datatables.net/examples/server_side/pipeline.html)
247
+
If you haven't already guessed, ajax is basically the signature of [jQuery.ajax](http://api.jquery.com/jquery.ajax/), which can be seen in this[jQuery DataTables ajax pipeline](https://datatables.net/examples/server_side/pipeline.html) code demonstration.
240
248
241
249
## Row Action Buttons
242
250
Use `data-action` attribute to automatically wire up any action button/elements. To render action button/element in a row, simply define dummy field like so:
@@ -291,8 +299,7 @@ Let say you have a column `description`, you can provide table head template for
291
299
292
300
Our default configuration compatible with Bootstrap4 is:
This is based on the configuration `lftiprB`, also see: https://datatables.net/reference/option/dom
@@ -318,4 +325,23 @@ window.open(url)
318
325
319
326
2. Alternatively, you can set `options.responsive=true` to use jQuery DataTable responsive plugin. **WARNING**: This plugin does not play well with `select-checkbox`, `master-details`, and many other features. It is recommended to use option 1 above.
320
327
321
-
# MIT
328
+
## Master-details pattern
329
+
`details` configuration allow you to create template for displaying details row in Master-details pattern. Schema:
330
+
```javascript
331
+
{
332
+
index:'a number (start at 1) representing the column position',
333
+
template:'the template where {{ data.column }} is the item/row data',
334
+
render:'provide a custom render function as alternative to template'
335
+
}
336
+
```
337
+
338
+
## Tips
339
+
If you're like us, you want to write as little code as possible, as in, application of the DRY Principal. This mean the UI has a standard look/feel/behavior; where toolbar, search, and other controls are place at specific location. So this mean you want to wrap this component inside your own component? Our sample App give you a good idea on how to start. Below are a few things to consider:
340
+
341
+
1. Identify all properties of the new component and howto translate into this component. Example: hidePageLength -> opts.lengthChange, hideQuickSearch -> v-if on quickSearch form, hideToolbar -> v-if on toolbar div, etc...
342
+
2. Identify methods to wrap, i.e. your component API: reload, getServerParams, etc...
343
+
3. Wrap individual action events you want to expose, or simply wrap with v-on="$listeners" to pipe all events from this component to your component.
344
+
345
+
## License
346
+
347
+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
0 commit comments