stimulus_rails_datatables 0.1.1 → 0.1.2
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.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d839615241e07844f4051bda906e5b0678c4a2e41072598c284966379ba8a576
|
|
4
|
+
data.tar.gz: 59f3872b9593296872b1838af1039f67687ffeab0ef875de5d36339053f370bd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fd41c028f9d65c93716f8d9a1317966271637c1c5f368bd623d7f1ad86bd39dbc59603d6dd31f025042c16d78e11fe37559cc4198bdcb13e417e67a1b9842609
|
|
7
|
+
data.tar.gz: aee985f8fa8699cc7280dc387c60db55976acaf869b2f16d550012ffe5c2e804c31dadffab7d2a5b8ecb5b9eb148fd8c192c8a572428fa9d0c3a94291020abf2
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import DataTable from 'datatables.net-responsive-bs5'
|
|
2
2
|
|
|
3
|
+
// Set global DataTables default for orderSequence
|
|
4
|
+
Object.assign(DataTable.defaults.column, {
|
|
5
|
+
orderSequence: ['desc', 'asc']
|
|
6
|
+
})
|
|
7
|
+
|
|
3
8
|
class AppDataTable {
|
|
4
9
|
constructor(selector, options) {
|
|
5
10
|
// Initialize the DataTable just like the original one
|
|
@@ -75,17 +75,15 @@ export default class extends Controller {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
initializeDataTable(url = this.sourceValue) {
|
|
78
|
-
const datatableId = this.idValue
|
|
79
|
-
const datatableWrapper = document.getElementById(`${datatableId}_wrapper`)
|
|
80
|
-
let appDataTable = null
|
|
78
|
+
const datatableId = this.idValue
|
|
79
|
+
const datatableWrapper = document.getElementById(`${datatableId}_wrapper`)
|
|
80
|
+
let appDataTable = null
|
|
81
81
|
|
|
82
82
|
if (datatableWrapper === null) {
|
|
83
|
-
Turbo.cache.exemptPageFromCache()
|
|
83
|
+
Turbo.cache.exemptPageFromCache()
|
|
84
84
|
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
appDataTable = new AppDataTable(`#${datatableId}`, {
|
|
88
|
-
lengthMenu: config.lengthMenu,
|
|
85
|
+
const options = {
|
|
86
|
+
lengthMenu: [[10, 25, 50, 100], [10, 25, 50, 100]],
|
|
89
87
|
searching: this.searchingValue,
|
|
90
88
|
lengthChange: this.lengthChangeValue,
|
|
91
89
|
processing: this.processingValue,
|
|
@@ -96,9 +94,28 @@ export default class extends Controller {
|
|
|
96
94
|
order: this.orderValue,
|
|
97
95
|
columns: this.columnsValue,
|
|
98
96
|
responsive: true,
|
|
99
|
-
language:
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
language: {
|
|
98
|
+
processing: '<div class="spinner-border"></div><div class="mt-2">Loading...</div>',
|
|
99
|
+
lengthMenu: 'show <span class="px-2">_MENU_</span> entries'
|
|
100
|
+
},
|
|
101
|
+
layout: {
|
|
102
|
+
topStart: 'pageLength',
|
|
103
|
+
topEnd: 'search',
|
|
104
|
+
bottomStart: 'info',
|
|
105
|
+
bottomEnd: 'paging'
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Add drawCallback to dispatch custom event
|
|
110
|
+
const appDataTable = new AppDataTable(`#${datatableId}`, options).table
|
|
111
|
+
if (appDataTable) {
|
|
112
|
+
appDataTable.on('draw', () => {
|
|
113
|
+
this.element.dispatchEvent(new CustomEvent('datatable:drawn', {
|
|
114
|
+
bubbles: true,
|
|
115
|
+
detail: { table: appDataTable }
|
|
116
|
+
}))
|
|
117
|
+
})
|
|
118
|
+
}
|
|
102
119
|
}
|
|
103
120
|
|
|
104
121
|
return appDataTable
|