stimulus_rails_datatables 0.4.0 → 0.5.1

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: 33857a74b843142081e2c836a7ca6b9ea3478b5de62c641397de780174b3365c
4
- data.tar.gz: fc7ceebc44032ec83db84357e9472c981c011f927581d051c5ed75d9de2785a1
3
+ metadata.gz: bbb9263b496e3deed5f28f35c19530d54cdc311a032da2eeeefb60c0c9dfa07d
4
+ data.tar.gz: 613bcfbd3ce0dd842d0bf1a3067b91ddb24cb5d773340726ae2851cd17040a15
5
5
  SHA512:
6
- metadata.gz: 496590e1f982a96b81f0c65e4ae6f577f82b9d59bb3a6638e294a3fbeff96d391e92552b1f352316e4864f3c8a70fe4846bf01ae6cd955f046818b111e88d0f7
7
- data.tar.gz: 886217d0aab41163e3d282e80c9144ada0f4b025f190753ce95c76fbfb9294ea65791ee1b078f75391b5a0e38b1bef4b4d7d71b4857223969fe20415903cb752
6
+ metadata.gz: 5619dd1eff78003687b588989cad96c353f52309eb184830764a5a42504033a61b5832bfc31fce8ef3fc856af7c4df30ebebc6554c3cfc1bb041b8a8b1c73ca7
7
+ data.tar.gz: d24f5d85abafab0b8dd73fd9ca3be0832efad5bdfc60caa98b2f0aa44990390792211432a46124ec6169fc54474787477dcbcb3e3fe282190c9b8d29fe1b6244
data/CHANGELOG.md CHANGED
@@ -5,6 +5,70 @@ 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.5.1] - 2026-07-28
9
+
10
+ ### Changed
11
+ - Updated system dependencies
12
+ - Bumped concurrent-ruby, erb, json, loofah, net-imap, parser, rails-html-sanitizer, and rubocop; updated Bundler version
13
+
14
+ ## [0.5.0] - 2026-06-08
15
+
16
+ ### Added
17
+ - Additional data handling for DataTables, with the JavaScript controller now dispatching additional-data events
18
+ - Updated README with usage details for the new additional data events
19
+
20
+ ## [0.4.0] - 2026-06-05
21
+
22
+ ### Added
23
+ - Custom header support in the DataTable helper
24
+ - Support for dependent location filters, with enhancements to the filter controller
25
+
26
+ ## [0.3.1] - 2026-01-14
27
+
28
+ ### Changed
29
+ - Updated the filter controller's local storage handling
30
+
31
+ ## [0.3.0] - 2026-01-09
32
+
33
+ ### Added
34
+ - `set_value` option for filters, allowing programmatic selection of filter values
35
+
36
+ ## [0.2.3] - 2025-12-17
37
+
38
+ ### Changed
39
+ - Enhanced DataTables configuration handling and updated installation instructions
40
+
41
+ ## [0.2.2] - 2025-12-17
42
+
43
+ ### Fixed
44
+ - Fixed initializer for ActionController loading in the Engine
45
+
46
+ ## [0.2.1] - 2025-12-02
47
+
48
+ ### Added
49
+ - `scrollX` and `stateSave` configuration options for datatables
50
+
51
+ ## [0.2.0] - 2025-12-01
52
+
53
+ ### Added
54
+ - `scroll_x` option support
55
+
56
+ ## [0.1.3] - 2025-11-25
57
+
58
+ ### Added
59
+ - `state_save` option to the `datatable_for` helper method
60
+
61
+ ## [0.1.2] - 2025-11-11
62
+
63
+ ### Changed
64
+ - Refactored DataTable initialization to use custom options and added a draw callback event
65
+ - Set a global DataTables default for `orderSequence`
66
+
67
+ ## [0.1.1] - 2025-11-09
68
+
69
+ ### Added
70
+ - Support for overriding DataTables configuration via a generated config file
71
+
8
72
  ## [0.1.0] - 2025-11-09
9
73
 
10
74
  ### Added
data/README.md CHANGED
@@ -96,7 +96,7 @@ Pass a block to render custom HTML in the column header instead of using `title:
96
96
  label: 'name',
97
97
  value: 'id',
98
98
  placeholder: 'Select Role',
99
- set_value: 1
99
+ set_value: 1
100
100
  }
101
101
  ) %>
102
102
 
@@ -233,6 +233,40 @@ class UserDatatable < StimulusRailsDatatables::BaseDatatable
233
233
  end
234
234
  ```
235
235
 
236
+ ### Additional Data
237
+
238
+ You can return extra fields alongside the standard DataTables JSON response by defining `additional_data` in your datatable class. This is useful for displaying aggregate stats (e.g. counts, totals) that are scoped to the current filtered result set.
239
+
240
+ ```ruby
241
+ class OrdersDatatable < StimulusRailsDatatables::BaseDatatable
242
+ def additional_data
243
+ { unread_orders_count: get_raw_records.where(is_read: false).count }
244
+ end
245
+
246
+ # ...
247
+ end
248
+ ```
249
+
250
+ Any element with a `data-datatable-field` attribute matching a key from `additional_data` will have its text content updated automatically after every draw (page change, sort, filter):
251
+
252
+ ```html
253
+ <span data-datatable-field="unread_orders_count">0</span> unread orders
254
+ ```
255
+
256
+ When you have **multiple datatables on the same page**, scope the element to a specific table using `data-for-datatable`:
257
+
258
+ ```html
259
+ <span data-datatable-field="unread_orders_count" data-for-datatable="orders-table">0</span>
260
+ ```
261
+
262
+ You can also listen for the `datatable:additional-data` event for custom JavaScript handling:
263
+
264
+ ```javascript
265
+ document.addEventListener('datatable:additional-data', (e) => {
266
+ console.log(e.detail) // { unread_orders_count: 5 }
267
+ })
268
+ ```
269
+
236
270
  ### JavaScript API
237
271
 
238
272
  ```javascript
@@ -127,6 +127,34 @@ export default class extends Controller {
127
127
  detail: { table: appDataTable }
128
128
  }))
129
129
  })
130
+
131
+ // Dispatch additional_data returned by the server alongside standard DataTables fields
132
+ const STANDARD_DT_KEYS = new Set(['draw', 'recordsTotal', 'recordsFiltered', 'data', 'error'])
133
+ appDataTable.on('xhr', (_e, _settings, json) => {
134
+ if (!json) return
135
+ const additionalData = Object.fromEntries(
136
+ Object.entries(json).filter(([key]) => !STANDARD_DT_KEYS.has(key))
137
+ )
138
+ if (Object.keys(additionalData).length === 0) return
139
+
140
+ // Dispatch event so consumers can react programmatically
141
+ this.element.dispatchEvent(new CustomEvent('datatable:additional-data', {
142
+ bubbles: true,
143
+ detail: additionalData
144
+ }))
145
+
146
+ // Auto-update elements: <span data-datatable-field="unread_orders_count">
147
+ // Scope with optional data-for-datatable="<id>" to support multiple tables per page
148
+ // Single DOM query for all field elements, then group by field name to avoid N queries per key
149
+ document.querySelectorAll('[data-datatable-field]').forEach(el => {
150
+ const key = el.dataset.datatableField
151
+ if (!(key in additionalData)) return
152
+ const forId = el.dataset.forDatatable
153
+ if (!forId || forId === datatableId) {
154
+ el.textContent = additionalData[key]
155
+ }
156
+ })
157
+ })
130
158
  }
131
159
  }
132
160
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StimulusRailsDatatables
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stimulus_rails_datatables
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Den Meralpis
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
143
  requirements: []
144
- rubygems_version: 4.0.10
144
+ rubygems_version: 4.0.16
145
145
  specification_version: 4
146
146
  summary: Rails integration for DataTables with filters and remote data support
147
147
  test_files: []