Skip to content

Commit b70633e

Browse files
committed
add render to master/details
1 parent b40c434 commit b70633e

File tree

9 files changed

+69
-31
lines changed

9 files changed

+69
-31
lines changed

README.md

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ npm install vue-datatables-net
3131
```
3232

3333
## 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.
3535

36-
> Example of required imports for Bootstrap 4:
36+
> Example of imports for Bootstrap 4:
3737
3838
```html
3939
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
@@ -74,7 +74,7 @@ import 'datatables.net-select-bs4/css/select.bootstrap4.min.css';
7474

7575
> See example [App](https://niiknow.github.io/vue-datatables-net/)
7676
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
7878

7979
**NOTE:**
8080
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: {
8787
}
8888
```
8989

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:
9191
* PHP - https://github.com/lampjunkie/php-datatables
9292
* PHP Symphony - https://github.com/stwe/DatatablesBundle
9393
* PHP Laravel - https://github.com/yajra/laravel-datatables
@@ -138,14 +138,14 @@ Our component parameters:
138138
type: Object
139139
},
140140
/**
141-
* True to enable multi-select checkboxes
141+
* The select-checkbox column index (start at 1)
142142
* Current implementation require datatables.net-select
143143
*
144-
* @type Boolean
144+
* @type Number
145145
*/
146-
selectable: {
147-
type: Boolean
148-
}
146+
selectCheckbox: {
147+
type: Number
148+
},
149149
/**
150150
* Provide custom local data loading. Warning: this option has not been
151151
* thoroughly tested. Please use ajax and serverSide instead.
@@ -162,6 +162,14 @@ Our component parameters:
162162
*/
163163
hideFooter: {
164164
type: Boolean
165+
},
166+
/**
167+
* The details column configuration of master/details.
168+
*
169+
* @type {Object}
170+
*/
171+
details: {
172+
type: Object
165173
}
166174
}
167175
```
@@ -187,18 +195,18 @@ fields: {
187195
- `className` set column class names
188196
- `defaultContent` provide default html when no data available
189197
- `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.
191199

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`.
193201
194202
One `Purpose` of this component is to extend jQuery DataTables function and features, example:
195203
* 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 per column 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.
198206
* Having schema also allow future features, such as: support of editable column/cell.
199207

200208
## 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)
202210

203211
i.e, something like:
204212
```javascript
@@ -236,7 +244,7 @@ opts: {
236244

237245
```
238246

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.
240248

241249
## Row Action Buttons
242250
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
291299
292300
Our default configuration compatible with Bootstrap4 is:
293301
```html
294-
"<'row'<'col-sm-12'tr>>" +
295-
"<'row vdtnet-footer'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'pl>>"
302+
"tr<'row vdtnet-footer'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'pl>>"
296303
```
297304
298305
This is based on the configuration `lftiprB`, also see: https://datatables.net/reference/option/dom
@@ -318,4 +325,23 @@ window.open(url)
318325
319326
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.
320327
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

Comments
 (0)