stimulus_rails_datatables 0.6.0 → 0.7.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +16 -1
- data/app/assets/javascripts/stimulus_rails_datatables/config.js +4 -1
- data/app/assets/javascripts/stimulus_rails_datatables/datatables_controller.js +7 -2
- data/app/assets/javascripts/stimulus_rails_datatables/filter_controller.js +7 -3
- data/app/helpers/stimulus_rails_datatables/datatable_helper.rb +3 -1
- data/lib/generators/stimulus_rails_datatables/install/templates/datatables_config.js +4 -1
- data/lib/stimulus_rails_datatables/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6c52d575fdf1e4bf88eb1cdf3b581ed80ec4c6956b1d5f0c3a60b90f99d2e3f2
|
|
4
|
+
data.tar.gz: 9bf301decccb7e7490972346183d73fa25d659088383521ff8b825b6bc83ac5e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 61e84f397c85ad598f98b47f7451e454fa6fae7e8e707fee9b9281829feecab1e151be8a387d4ea19cad63ac3d71f3e3c301f756dc2f20f07f9b7948a0f830ea
|
|
7
|
+
data.tar.gz: 780dddf9239013c1fb8444a0d2ffeaab370829cfbffcd0827d23f5545f8e082d3740403b8e4854e52ed0185cf8eccd683decd3eb9d6353e2b8e327ac7113c73d
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,24 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.7.0] - 2026-09-25
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- `resetPaging` global config option (`window.datatablesConfig` or `setDatatablesConfig`) to go back to the first page when filters change; defaults to `false`
|
|
12
|
+
- `reset_paging` option for the `datatable_for` helper, which overrides the global `resetPaging` value per datatable
|
|
13
|
+
|
|
14
|
+
## [0.6.0] - 2026-08-03
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
- Tom-Select support for remote filter selects via the `tomselect` option
|
|
18
|
+
- `multiple` option for remote filter selects, sending the selected values as array params (`filters[key][]=`)
|
|
19
|
+
- `set_values` remote option to preselect multiple values
|
|
20
|
+
- Summary label showing the number of selected items on Tom-Select multi-selects
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
- The `location` filter's barangay select is now a Tom-Select multi-select
|
|
24
|
+
- The filter controller imports `tom-select`, so the host app must pin it in its importmap
|
|
25
|
+
|
|
8
26
|
## [0.5.1] - 2026-07-28
|
|
9
27
|
|
|
10
28
|
### Changed
|
data/README.md
CHANGED
|
@@ -335,10 +335,25 @@ window.datatablesConfig = {
|
|
|
335
335
|
},
|
|
336
336
|
|
|
337
337
|
// Length menu options
|
|
338
|
-
lengthMenu: [[10, 25, 50, 100], [10, 25, 50, 100]]
|
|
338
|
+
lengthMenu: [[10, 25, 50, 100], [10, 25, 50, 100]],
|
|
339
|
+
|
|
340
|
+
// Go back to the first page when filters change (default: false)
|
|
341
|
+
resetPaging: true
|
|
339
342
|
}
|
|
340
343
|
```
|
|
341
344
|
|
|
345
|
+
### Resetting Pagination on Filter Change
|
|
346
|
+
|
|
347
|
+
By default, changing a filter reloads the datatable and keeps the current page. Set `resetPaging: true` in `window.datatablesConfig` to jump back to the first page for every datatable, or override it per table with `reset_paging:`:
|
|
348
|
+
|
|
349
|
+
```ruby
|
|
350
|
+
<%= datatable_for 'users-table', source: users_path, reset_paging: false do |dt| %>
|
|
351
|
+
<% dt.column :name %>
|
|
352
|
+
<% end %>
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
Leave `reset_paging:` out to use the global value. Restoring saved filters on page load never resets the page, so the page kept by `state_save` is not lost.
|
|
356
|
+
|
|
342
357
|
### Available Stimulus Controllers
|
|
343
358
|
|
|
344
359
|
The gem automatically registers the following Stimulus controllers:
|
|
@@ -30,7 +30,10 @@ let datatablesConfig = {
|
|
|
30
30
|
},
|
|
31
31
|
|
|
32
32
|
// Length menu options
|
|
33
|
-
lengthMenu: [[10, 25, 50, 100], [10, 25, 50, 100]]
|
|
33
|
+
lengthMenu: [[10, 25, 50, 100], [10, 25, 50, 100]],
|
|
34
|
+
|
|
35
|
+
// Go back to the first page when filters change (override per table with datatable_for reset_paging:)
|
|
36
|
+
resetPaging: false
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
// Function to let the app override defaults
|
|
@@ -17,7 +17,8 @@ export default class extends Controller {
|
|
|
17
17
|
pagingType: { type: String, default: 'simple_numbers' },
|
|
18
18
|
searching: { type: Boolean, default: true },
|
|
19
19
|
lengthChange: { type: Boolean, default: true },
|
|
20
|
-
responsive: { type: Boolean, default: true }
|
|
20
|
+
responsive: { type: Boolean, default: true },
|
|
21
|
+
resetPaging: Boolean
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
connect() {
|
|
@@ -89,7 +90,8 @@ export default class extends Controller {
|
|
|
89
90
|
const config = {
|
|
90
91
|
language: { ...defaultConfig.language, ...(userConfig.language || {}) },
|
|
91
92
|
layout: { ...defaultConfig.layout, ...(userConfig.layout || {}) },
|
|
92
|
-
lengthMenu: userConfig.lengthMenu || defaultConfig.lengthMenu
|
|
93
|
+
lengthMenu: userConfig.lengthMenu || defaultConfig.lengthMenu,
|
|
94
|
+
resetPaging: userConfig.resetPaging ?? defaultConfig.resetPaging
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
const responsiveValue = this.responsiveValue
|
|
@@ -107,6 +109,9 @@ export default class extends Controller {
|
|
|
107
109
|
responsive: this.responsiveValue,
|
|
108
110
|
language: config.language,
|
|
109
111
|
layout: config.layout,
|
|
112
|
+
// Not a DataTables option; the filter controller reads it back via datatable.init()
|
|
113
|
+
// Per-table value (datatable_for reset_paging:) wins over the global config
|
|
114
|
+
resetPaging: this.hasResetPagingValue ? this.resetPagingValue : !!config.resetPaging,
|
|
110
115
|
initComplete: function() {
|
|
111
116
|
if (responsiveValue === false) {
|
|
112
117
|
// Add overflow-x only to the table wrapper (not the whole layout) this is alternative of scrollX
|
|
@@ -136,7 +136,8 @@ export default class extends Controller {
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
// reloadAppDatatable reloads the datatable with current params
|
|
139
|
-
|
|
139
|
+
// pass resetPaging true/false to force it, otherwise the datatable's resetPaging setting is used
|
|
140
|
+
async reloadAppDatatable(resetPaging) {
|
|
140
141
|
var id = this.element.dataset.filterDatatableId
|
|
141
142
|
|
|
142
143
|
if (!id) {
|
|
@@ -147,7 +148,9 @@ export default class extends Controller {
|
|
|
147
148
|
const datatableUrl = datatable.ajax.url().split('?')[0]
|
|
148
149
|
const params = this.toQuery(this.currentParams())
|
|
149
150
|
|
|
150
|
-
datatable.
|
|
151
|
+
if (typeof resetPaging !== 'boolean') resetPaging = datatable.init()?.resetPaging === true
|
|
152
|
+
|
|
153
|
+
datatable.ajax.url(`${datatableUrl}?${params}`).load(null, resetPaging)
|
|
151
154
|
}
|
|
152
155
|
}
|
|
153
156
|
|
|
@@ -296,8 +299,9 @@ export default class extends Controller {
|
|
|
296
299
|
localStorage.setItem(`filterState:${this.filterDtId}`, JSON.stringify(payload))
|
|
297
300
|
} catch (e) {}
|
|
298
301
|
|
|
302
|
+
// restoring saved filters is not a filter change, so keep the page restored by stateSave
|
|
299
303
|
if (Object.keys(payload[rootKey] || {}).length > 0) {
|
|
300
|
-
this.reloadAppDatatable()
|
|
304
|
+
this.reloadAppDatatable(false)
|
|
301
305
|
}
|
|
302
306
|
}
|
|
303
307
|
|
|
@@ -8,6 +8,7 @@ module StimulusRailsDatatables
|
|
|
8
8
|
length_change = options.fetch(:length_change, true)
|
|
9
9
|
state_save = options.fetch(:state_save, true)
|
|
10
10
|
responsive = options.fetch(:responsive, true)
|
|
11
|
+
reset_paging = options[:reset_paging] # nil falls back to the global resetPaging config
|
|
11
12
|
columns = []
|
|
12
13
|
|
|
13
14
|
capture(DatatableBuilder.new(self, columns), &block)
|
|
@@ -22,7 +23,8 @@ module StimulusRailsDatatables
|
|
|
22
23
|
datatable_searching_value: searching,
|
|
23
24
|
datatable_length_change_value: length_change,
|
|
24
25
|
datatable_state_save_value: state_save,
|
|
25
|
-
datatable_responsive_value: responsive
|
|
26
|
+
datatable_responsive_value: responsive,
|
|
27
|
+
datatable_reset_paging_value: reset_paging
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
content_tag(:div, data: data) do
|
|
@@ -41,5 +41,8 @@ window.datatablesConfig = {
|
|
|
41
41
|
},
|
|
42
42
|
|
|
43
43
|
// Length menu options
|
|
44
|
-
lengthMenu: [[10, 25, 50, 100], [10, 25, 50, 100]]
|
|
44
|
+
lengthMenu: [[10, 25, 50, 100], [10, 25, 50, 100]],
|
|
45
|
+
|
|
46
|
+
// Go back to the first page when filters change (override per table with datatable_for reset_paging:)
|
|
47
|
+
resetPaging: false
|
|
45
48
|
}
|