Skip to content

Commit

Permalink
add create event
Browse files Browse the repository at this point in the history
  • Loading branch information
noogen committed Aug 28, 2019
1 parent 529abb5 commit e1c773a
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 26 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,26 @@ One `Purpose` of this component is to extend jQuery DataTables function and feat
* 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.
* Having schema also allow for future features, such as editable column/cell.

### events
Custom events for this component.
```html
<vdtnet-table ...
@tableCreating="doSomethingImmediatelyAfterDataTableCreate"
@tableCreated="doSomethingImmediatelyAfterTableCreatedAndInitialized"
@reloaded="doSomethingAfterDataLoadOrReloaded"
/>
```

```js
doSomethingImmediatelyAfterTableCreatedAndInitialized(comp) {
// use comp.dataTable to access the jQuery DataTables object, example:
comp.dataTable.on( 'order.dt', function () { eventFired( 'Order' ); } )
}
```
- `tableCreating` this is immediately after jQuery(el).DataTable is called.
- `tableCreated` this is after we have initialized all the columns.
- `reloaded` this is after data has been load/reloaded

## Additional Headers
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)

Expand Down
4 changes: 3 additions & 1 deletion example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ var myUniqueId = 1;
var $el = jq(vm.$refs.table); // console.log(vm.options.buttons)

vm.dataTable = $el.DataTable(vm.options);
vm.$emit('table-creating', vm);

if (vm.selectCheckbox) {
// handle select all checkbox
Expand Down Expand Up @@ -817,8 +818,9 @@ var myUniqueId = 1;
tr.addClass('master');
}
});
} // finally, load data
}

vm.$emit('table-created', vm); // finally, load data

if (vm.dataLoader) {
vm.reload();
Expand Down
2 changes: 1 addition & 1 deletion example/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/index.js": "/index.js?id=ad7b8d4944a8f079b5a3",
"/index.js.map": "/index.js.map?id=19d02234de31f6b15dc7"
"/index.js": "/index.js?id=ac91b689ff131831cbbc",
"/index.js.map": "/index.js.map?id=154eed62452287a86ec0"
}
40 changes: 22 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vue-datatables-net",
"description": "Vue jQuery DataTables.net wrapper component",
"version": "1.1.7",
"version": "1.1.8",
"author": "[email protected]",
"license": "MIT",
"main": "lib/index.js",
Expand Down Expand Up @@ -36,7 +36,7 @@
"devDependencies": {
"@babel/core": "^7.5.5",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"babel-eslint": "^10.0.2",
"babel-eslint": "^10.0.3",
"bootstrap": "^4.3.1",
"browser-sync": "^2.26.7",
"browser-sync-webpack-plugin": "^2.0.1",
Expand Down
3 changes: 3 additions & 0 deletions src/VdtnetTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ export default {
// console.log(vm.options.buttons)
vm.dataTable = $el.DataTable(vm.options)
vm.$emit('table-creating', vm)
if (vm.selectCheckbox) {
// handle select all checkbox
Expand Down Expand Up @@ -412,6 +413,8 @@ export default {
})
}
vm.$emit('table-created', vm)
// finally, load data
if (vm.dataLoader) {
vm.reload()
Expand Down

0 comments on commit e1c773a

Please sign in to comment.