Skip to content

Commit d04c26e

Browse files
committed
update doc
1 parent 64be101 commit d04c26e

File tree

8 files changed

+129
-76
lines changed

8 files changed

+129
-76
lines changed

README.md

Lines changed: 78 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
# vue-datatables-net
22
> Vue jQuery DataTable.net wrapper component
33
4-
This library is simply a wrapper for [jQuery DataTable](https://datatables.net/). It's a tiny package that doesn't include anything, not even the datatable.net core library. Per example below, you basically have to include only/any datatable.net package(s) that you need.
4+
This library is a wrapper for [jQuery DataTable](https://datatables.net/). It's a tiny package that doesn't include anything, not even the datatables.net core library.
55

6-
The initial focus/design of this library is to use with ajax/server-side endpoint. For local data, simply use native methods like so:
6+
The initial focus/design of this library is to use with ajax/server-side endpoint. Though, since it is a datatables.net wrapper, local data use/loading is simply:
77

88
```javascript
99
component.dataTable.clear().draw();
1010
component.dataTable.rows.add(newDataArray).draw();
1111
```
12+
1213
## Development
1314
This library uses the NodeJS library `laravel-mix` to simplify build and packaging.
1415

15-
To run locally, it automatically launch firefox:
16+
To run locally (automatically launch firefox):
1617
```
1718
npm run watch
1819
```
@@ -37,20 +38,22 @@ import VdtnetTable from 'vue-datatables-net'
3738
import 'datatables.net-bs4'
3839
3940
/*
40-
// you can import these if needed
41-
// this import all buttons that we need
41+
// you can import these on a needed basis
42+
// this import all buttons that we need, for
43+
// use with opts: { buttons: ['csv', 'print', ...]}
4244
import 'datatables.net-buttons/js/dataTables.buttons.js';
4345
import 'datatables.net-buttons/js/buttons.html5.js';
4446
import 'datatables.net-buttons/js/buttons.print.js';
4547
import 'datatables.net-responsive/js/dataTables.responsive.js';
4648
47-
// import the rest
49+
// import any datatable extension as you would when using it raw
4850
import 'datatables.net-buttons-bs4'
4951
import 'datatables.net-responsive-bs4'
5052
import 'datatables.net-fixedheader-bs4'
5153
import 'datatables.net-scroller-bs4';
5254
import 'datatables.net-select-bs4';
5355
56+
// import any styles to support the packages you import above
5457
import 'datatables.net-bs4/css/dataTables.bootstrap4.min.css';
5558
import 'datatables.net-buttons-bs4/css/buttons.bootstrap4.min.css';
5659
import 'datatables.net-responsive-bs4/css/responsive.bootstrap4.min.css';
@@ -60,12 +63,12 @@ import 'datatables.net-select-bs4/css/select.bootstrap4.min.css';
6063
</script>
6164
```
6265

63-
> Use it like the example App
66+
> See example [App](https://niiknow.github.io/vue-datatables-net/)
6467
65-
This 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
68+
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
6669

6770
**NOTE:**
68-
The example app use free API endpoint from typicode [https://jsonplaceholder.typicode.com] so it's not jQuery DataTable.net compatible. As a result, we have to define a dataSrc wrapper like so:
71+
The example App use free API endpoint from typicode [https://jsonplaceholder.typicode.com] so it's not jQuery DataTable.net queryable. As a result, we have to define a dataSrc wrapper like so:
6972
```
7073
ajax: {
7174
url: 'https://jsonplaceholder.typicode.com/users',
@@ -75,55 +78,86 @@ ajax: {
7578
}
7679
```
7780

78-
Some example server-side ajax parsers implementation:
81+
Here are some server-side ajax parser implementation:
7982
* PHP - https://github.com/lampjunkie/php-datatables
8083
* PHP Symphony - https://github.com/stwe/DatatablesBundle
8184
* PHP Laravel - https://github.com/yajra/laravel-datatables
8285
* dotNET - https://github.com/ALMMa/datatables.aspnet, https://github.com/garvincasimir/csharp-datatables-parser
8386
* NodeJS - https://github.com/jpravetz/node-datatable
8487
* Rails - https://github.com/jbox-web/ajax-datatables-rails
8588

86-
> Or simply with url that can handle datatable.net server-side endpoint:
87-
88-
```html
89-
<template>
90-
<div id="app">
91-
<vdtnet-table :fields="fields" url="/some/api/using/yajra/laravel-datatables/or/similar" />
92-
</div>
93-
</template>
89+
## Documentation
90+
Since it's a wrapper, all/most features are provided by the [jQuery DataTable](https://datatables.net/manual/) library.
9491

95-
<script>
96-
import VdtnetTable from 'vue-datatables-net'
97-
import 'datatables.net-bs4'
92+
More documentations below.
9893

99-
export default {
100-
name: 'app',
101-
components: { VdtnetTable },
102-
data() {
103-
const vm = this
104-
105-
return {
106-
fields: {
107-
id: { label: 'ID', sortable: true },
108-
name: { label: 'Name', sortable: true, searchable: true },
109-
username: { label: 'Username', sortable: false, searchable: true },
110-
email: { label: 'Email' },
111-
phone: { label: 'Phone' },
112-
website: { label: 'Website' }
113-
}
114-
}
94+
## Parameters
95+
Our component parameters:
96+
```javascript
97+
props: {
98+
// Set the table classes you wish to use, default with bootstrap4
99+
// but you can override with: themeforest, foundation, etc..
100+
className: {
101+
type: String,
102+
default: 'table table-striped table-bordered dt-responsive nowrap w-100'
103+
},
104+
// the options object: https://datatables.net/manual/options
105+
opts: {
106+
type: Object
107+
},
108+
/**
109+
* List all fields to be converted to opts columns
110+
*
111+
* @type {Object}
112+
*/
113+
fields: {
114+
type: Object
115+
},
116+
/**
117+
* Pass in DataTables.Net loaded jQuery to resolve
118+
* any multiple loaded browser jQuery conflict
119+
*
120+
* @type {Object}
121+
*/
122+
jquery: {
123+
type: Object
124+
},
125+
/**
126+
* True to enable multi-select checkboxes
127+
* Current implementation require datatables.net-select
128+
*
129+
* @type Boolean
130+
*/
131+
selectable: {
132+
type: Boolean
115133
}
116-
}
117-
</script>
134+
},
118135
```
119136

120-
## Documentation
121-
Since it's a wrapper, all/most features are provided by the [jQuery DataTable](https://datatables.net/manual/) library.
137+
`fields` is an schema object that identify all datatables.net columns, example:
122138

123-
More documentations below.
139+
Example:
140+
```json
141+
fields: {
142+
_id: { label: "ID" },
143+
title: { label: "Title", searchable: true, sortable: true },
144+
type: { label: "Type" }
145+
}
146+
```
147+
148+
### Field properties
149+
- `label` Title for display
150+
- `searchable` true to enable search of field
151+
- `sortable` false to disable sorting
152+
- `name` to override the name
153+
- `visible` false to hide
154+
- `width` to provide custom width
155+
- `className` set column class names
156+
- `defaultContent` provide default html for null
157+
- `render` custom cell rendering function https://datatables.net/reference/option/columns.render
124158

125159
## Additional Headers
126-
Since options are completely exposed, simply use the native method per [jQuery DataTable example](https://editor.datatables.net/manual/security#Prevention)
160+
Many server-side usage require CSRF and/or API token headers. Since options are completely exposed, simply use the native method per [jQuery DataTable example](https://editor.datatables.net/manual/security#Prevention)
127161

128162
i.e, something like:
129163
```javascript
@@ -141,7 +175,7 @@ options: {
141175
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 DataTable ajax pipeline](https://datatables.net/examples/server_side/pipeline.html)
142176

143177
## Row Action Buttons
144-
Use `data-action` attribute to automatically wire up any action button/elements. To render action button/element in a row, simply define field like below (also, see example App):
178+
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:
145179
```javascript
146180
actions: {
147181
label: 'Actions',
@@ -150,11 +184,4 @@ actions: {
150184
}
151185
```
152186

153-
## Selectable
154-
> set this to enable datatable.net-select extension
155-
156-
```html
157-
<vdtnet-table :selectable="true" />
158-
```
159-
160187
# MIT

0 commit comments

Comments
 (0)