datatables.net-vue3 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,48 @@
1
+ export interface IData {
2
+ _dt: null | any;
3
+ oldData: Array<any>;
4
+ }
5
+ declare const Comp: import("vue").DefineComponent<{
6
+ ajax: null;
7
+ class: {
8
+ type: StringConstructor;
9
+ default: string;
10
+ };
11
+ columns: {
12
+ type: ArrayConstructor;
13
+ default: null;
14
+ };
15
+ data: {
16
+ type: ArrayConstructor;
17
+ default: null;
18
+ };
19
+ options: {
20
+ default: {};
21
+ };
22
+ }, unknown, IData, {}, {
23
+ dt(): any;
24
+ saveOld(d: any): void;
25
+ }, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
26
+ ajax: null;
27
+ class: {
28
+ type: StringConstructor;
29
+ default: string;
30
+ };
31
+ columns: {
32
+ type: ArrayConstructor;
33
+ default: null;
34
+ };
35
+ data: {
36
+ type: ArrayConstructor;
37
+ default: null;
38
+ };
39
+ options: {
40
+ default: {};
41
+ };
42
+ }>>, {
43
+ data: unknown[];
44
+ class: string;
45
+ columns: unknown[];
46
+ options: {};
47
+ }>;
48
+ export default Comp;
@@ -0,0 +1,7 @@
1
+ import { Plugin } from 'vue';
2
+ import component from "./datatables.net-vue.vue";
3
+ declare type InstallableComponent = typeof component & {
4
+ install: Exclude<Plugin['install'], undefined>;
5
+ };
6
+ declare const _default: InstallableComponent;
7
+ export default _default;
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "datatables.net-vue3",
3
+ "version": "1.0.0",
4
+ "description": "Vue3 component for DataTables",
5
+ "main": "dist/datatables.net-vue.ssr.js",
6
+ "browser": "dist/datatables.net-vue.esm.js",
7
+ "module": "dist/datatables.net-vue.esm.js",
8
+ "unpkg": "dist/datatables.net-vue.min.js",
9
+ "types": "dist/types/src/entry.esm.d.ts",
10
+ "files": [
11
+ "dist/*",
12
+ "src/**/*.vue"
13
+ ],
14
+ "sideEffects": false,
15
+ "scripts": {
16
+ "serve": "vue-cli-service serve dev/serve.ts",
17
+ "prebuild": "rimraf ./dist",
18
+ "build": "NODE_ENV=production rollup --config build/rollup.config.js",
19
+ "build:ssr": "NODE_ENV=production rollup --config build/rollup.config.js --format cjs",
20
+ "build:es": "NODE_ENV=production rollup --config build/rollup.config.js --format es",
21
+ "build:unpkg": "NODE_ENV=production rollup --config build/rollup.config.js --format iife",
22
+ "postbuild": "rimraf ./dist/types/dev ./dist/types/src/entry.d.ts"
23
+ },
24
+ "dependencies": {
25
+ "datatables.net": "^1.12.1",
26
+ "jquery": "^3.6.0"
27
+ },
28
+ "devDependencies": {
29
+ "@babel/core": "^7.14.6",
30
+ "@babel/preset-env": "^7.14.7",
31
+ "@babel/preset-typescript": "^7.14.5",
32
+ "@rollup/plugin-alias": "^3.1.2",
33
+ "@rollup/plugin-babel": "^5.3.0",
34
+ "@rollup/plugin-commonjs": "^14.0.0",
35
+ "@rollup/plugin-node-resolve": "^9.0.0",
36
+ "@rollup/plugin-replace": "^2.4.2",
37
+ "@types/jquery": "^3.5.14",
38
+ "@vue/cli-plugin-babel": "^4.5.13",
39
+ "@vue/cli-plugin-typescript": "^4.5.13",
40
+ "@vue/cli-service": "^4.5.13",
41
+ "@vue/compiler-sfc": "^3.0.11",
42
+ "@zerollup/ts-transform-paths": "^1.7.18",
43
+ "cross-env": "^7.0.3",
44
+ "minimist": "^1.2.5",
45
+ "postcss": "^8.2.10",
46
+ "rimraf": "^3.0.2",
47
+ "rollup": "^2.52.8",
48
+ "rollup-plugin-postcss": "^4.0.0",
49
+ "rollup-plugin-terser": "^7.0.2",
50
+ "rollup-plugin-typescript2": "^0.30.0",
51
+ "rollup-plugin-vue": "^6.0.0",
52
+ "ttypescript": "^1.5.12",
53
+ "typescript": "^4.0.3",
54
+ "vue": "^3.0.5"
55
+ },
56
+ "peerDependencies": {
57
+ "vue": "^3.0.5"
58
+ },
59
+ "engines": {
60
+ "node": ">=12"
61
+ },
62
+ "repository": {
63
+ "type": "git",
64
+ "url": "git+https://github.com/DataTables/Vue.git"
65
+ },
66
+ "author": {
67
+ "name": "SpryMedia Ltd",
68
+ "url": "http://datatables.net"
69
+ }
70
+ }
@@ -0,0 +1,124 @@
1
+ <script lang="ts">
2
+
3
+ import { defineComponent } from 'vue';
4
+
5
+ // Load in DataTables based and jQuery
6
+ import jQuery from 'jquery';
7
+ import * as DataTables from 'datatables.net';
8
+
9
+ export interface IData {
10
+ _dt: null | any,
11
+ oldData: Array<any>
12
+ }
13
+
14
+ // Register DataTables
15
+ (DataTables.default as any)(window, jQuery);
16
+
17
+ const Comp = defineComponent({
18
+ name: 'DataTable',
19
+ expose: [
20
+ 'dt',
21
+ ],
22
+ data(): IData {
23
+ return {
24
+ _dt: null,
25
+ oldData: [],
26
+ };
27
+ },
28
+ computed: {},
29
+ methods: {
30
+ dt() {
31
+ return this._dt;
32
+ },
33
+ saveOld(d: any) {
34
+ this.oldData = d.value
35
+ ? d.value.slice()
36
+ : d.slice();
37
+ }
38
+ },
39
+ mounted() {
40
+ // Component shown so we can initialise DataTables of the table now
41
+ let table = this.$el.querySelector('table');
42
+ let options: any = this.options;
43
+
44
+ if (this.data) {
45
+ options.data = this.data;
46
+ this.saveOld(options.data);
47
+ }
48
+
49
+ if (this.columns) {
50
+ options.columns = this.columns;
51
+ }
52
+
53
+ if (this.ajax) {
54
+ options.ajax = this.ajax;
55
+ }
56
+
57
+ this._dt = jQuery(table).DataTable(options);
58
+ },
59
+ beforeUnmount() {
60
+ this._dt.destroy(true);
61
+ },
62
+ props: {
63
+ ajax: null,
64
+ class: {
65
+ type: String,
66
+ default: '',
67
+ },
68
+ columns: {
69
+ type: Array,
70
+ default: null,
71
+ },
72
+ data: {
73
+ type: Array,
74
+ default: null,
75
+ },
76
+ options: {
77
+ default: {}
78
+ }
79
+ },
80
+ watch: {
81
+ data: {
82
+ handler(newVal) {
83
+ let known = this._dt.data().toArray();
84
+
85
+ // Find any new rows
86
+ for (let n of newVal) {
87
+ if (! known.includes(n)) {
88
+ this._dt.row.add(n);
89
+ }
90
+ }
91
+
92
+ // Remove any old rows
93
+ for (let k of known) {
94
+ if (! newVal.includes(k)) {
95
+ this._dt.row((_idx: any, d: any) => d === k).remove();
96
+ }
97
+ }
98
+
99
+ // Data in other rows might have changes, so we need to invalidate the rows
100
+ this._dt.rows().invalidate().draw(false);
101
+
102
+ this.saveOld(newVal);
103
+ },
104
+ deep: true
105
+ }
106
+ }
107
+ });
108
+
109
+ // Expose a static method that can be used to add extensions
110
+ Comp.use = function(lib: any) {
111
+ lib(window, jQuery);
112
+ }
113
+
114
+ export default Comp;
115
+
116
+ </script>
117
+
118
+ <template>
119
+ <div class="datatable" v-once>
120
+ <table :class="class">
121
+ <slot></slot>
122
+ </table>
123
+ </div>
124
+ </template>