json-rules-filter 1.0.25 → 1.0.27
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.
- package/package.json +1 -1
- package/readme.md +19 -2
- package/src/jquery.jsonRulesFilter.js +38 -4
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -88,6 +88,10 @@ $("#miFiltro").jsonRulesFilter(data,
|
|
|
88
88
|
onApply: function (rules, filteredData) {
|
|
89
89
|
console.log("Reglas:", rules);
|
|
90
90
|
console.log("Resultados:", filteredData);
|
|
91
|
+
},
|
|
92
|
+
onTakeSnapshot: function (reglas) {
|
|
93
|
+
console.log("Reglas:", rules);
|
|
94
|
+
console.log("Configuración de filtrado aplicada")
|
|
91
95
|
}
|
|
92
96
|
});
|
|
93
97
|
```
|
|
@@ -198,6 +202,16 @@ onApply: function (rules, filteredData) {
|
|
|
198
202
|
}
|
|
199
203
|
```
|
|
200
204
|
|
|
205
|
+
---
|
|
206
|
+
### onTakeSnapshot
|
|
207
|
+
|
|
208
|
+
Callback ejecutado al guardar filtros.
|
|
209
|
+
|
|
210
|
+
```javascript
|
|
211
|
+
onTakeSnapshot: function (rules) {
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
201
215
|
---
|
|
202
216
|
|
|
203
217
|
## 🧩 Tipos de filtros
|
|
@@ -277,6 +291,9 @@ $("#container-rules").jsonRulesFilter(empleados, {
|
|
|
277
291
|
});
|
|
278
292
|
|
|
279
293
|
$("#num-filters").html(reglas.length);
|
|
294
|
+
},
|
|
295
|
+
onTakeSnapshot: function (reglas) {
|
|
296
|
+
alert("Configuración de filtrado aplicada");
|
|
280
297
|
}
|
|
281
298
|
});
|
|
282
299
|
```
|
|
@@ -310,11 +327,11 @@ $("#container-rules").jsonRulesFilter(empleados, {
|
|
|
310
327
|
- Usa lógica AND entre reglas
|
|
311
328
|
- Basado en Select2
|
|
312
329
|
- Permite múltiples instancias
|
|
330
|
+
- Guardado de filtros en localStorage
|
|
331
|
+
- Exportar/importar reglas
|
|
313
332
|
|
|
314
333
|
---
|
|
315
334
|
|
|
316
335
|
## 💡 Ideas futuras
|
|
317
336
|
|
|
318
337
|
- Lógica OR
|
|
319
|
-
- Guardado de filtros
|
|
320
|
-
- Exportar/importar reglas
|
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
}(function ($) {
|
|
10
10
|
$.fn.jsonRulesFilter = function (data, options) {
|
|
11
11
|
|
|
12
|
+
const publicMethods = ['updateData', 'preloadRules', 'reset'];
|
|
13
|
+
|
|
12
14
|
// --- COMMAND MANAGEMENT (Method calling via string) ---
|
|
13
15
|
if (typeof data === 'string') {
|
|
14
16
|
const instance = $(this).data('rulesControl');
|
|
15
|
-
if (instance && typeof instance[data] === 'function') {
|
|
17
|
+
if (instance && typeof instance[data] === 'function' && publicMethods.includes(data)) {
|
|
16
18
|
return instance[data].apply(instance, Array.prototype.slice.call(arguments, 1));
|
|
17
19
|
}
|
|
18
20
|
return this;
|
|
@@ -42,10 +44,12 @@
|
|
|
42
44
|
title: { text: "Reglas de filtrado", className: "fs-6 fw-semibold" },
|
|
43
45
|
buttons: {
|
|
44
46
|
reset: { text: "Resetear", className: "fw-semibold link-danger link-offset-2 link-underline link-underline-opacity-0" },
|
|
47
|
+
save: { text: "Guardar", className: "fw-semibold link-primary link-offset-2 link-underline link-underline-opacity-0" },
|
|
45
48
|
dropdown: { text: "Añadir regla", className: "btn btn-secondary" },
|
|
46
49
|
apply: { text: "Aplicar regla", className: "btn btn-primary" },
|
|
47
50
|
},
|
|
48
|
-
onApply: function (filtros, datosFiltrados) { }
|
|
51
|
+
onApply: function (filtros, datosFiltrados) { },
|
|
52
|
+
onTakeSnapshot: function (filtros) { }
|
|
49
53
|
}, options);
|
|
50
54
|
|
|
51
55
|
return this.each(function () {
|
|
@@ -134,11 +138,31 @@
|
|
|
134
138
|
return rulesAplicated;
|
|
135
139
|
},
|
|
136
140
|
|
|
141
|
+
takeSnapshot: function(){
|
|
142
|
+
const self = this;
|
|
143
|
+
const rules = this.getAplicatedRules();
|
|
144
|
+
localStorage.setItem("jsonRulesFilterData", JSON.stringify(rules));
|
|
145
|
+
// EXECUTE onTakeSnapshot CALLBACK
|
|
146
|
+
if (typeof self.settings.onTakeSnapshot === 'function') {
|
|
147
|
+
// Pass rules summary and filtered array to the main program
|
|
148
|
+
self.settings.onTakeSnapshot.call(self.$contenedor, rules);
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
getSnapshot: function(){
|
|
153
|
+
const rules = localStorage.getItem("jsonRulesFilterData");
|
|
154
|
+
|
|
155
|
+
if(rules != null){
|
|
156
|
+
this.preloadRules(JSON.parse(rules));
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
|
|
137
160
|
// Initialize UI components
|
|
138
161
|
init: function () {
|
|
139
162
|
this.$contenedor.empty();
|
|
140
163
|
this.render();
|
|
141
164
|
this.bindEvents();
|
|
165
|
+
this.getSnapshot();
|
|
142
166
|
},
|
|
143
167
|
|
|
144
168
|
// Render main plugin skeleton
|
|
@@ -167,7 +191,10 @@
|
|
|
167
191
|
let template = `
|
|
168
192
|
<div class="d-flex justify-content-between">
|
|
169
193
|
<p class="${this.bs(this.settings.title.className)}">${this.settings.title.text}</p>
|
|
170
|
-
<
|
|
194
|
+
<div class="d-flex justify-content-between">
|
|
195
|
+
<p class="mr-2"><a class="${this.bs(this.settings.buttons.save.className)} save-rules-snapshot" href="#">${this.settings.buttons.save.text}</a></p>
|
|
196
|
+
<p><a class="${this.bs(this.settings.buttons.reset.className)} remove-rules-containers" href="#">${this.settings.buttons.reset.text}</a></p>
|
|
197
|
+
</div>
|
|
171
198
|
</div>
|
|
172
199
|
<div class="py-2 container-rules-filters"></div>
|
|
173
200
|
<div class="mt-2">
|
|
@@ -183,6 +210,7 @@
|
|
|
183
210
|
<button type="button" id="apply-rules-btn" class="${this.bs(this.settings.buttons.apply.className)}">${this.settings.buttons.apply.text}</button>
|
|
184
211
|
</div>
|
|
185
212
|
</div>`;
|
|
213
|
+
|
|
186
214
|
this.$contenedor.append(template);
|
|
187
215
|
if (this.settings.scrollY !== false) {
|
|
188
216
|
const maxHeight = typeof this.settings.scrollY === 'number' ?
|
|
@@ -244,6 +272,12 @@
|
|
|
244
272
|
self.reset();
|
|
245
273
|
});
|
|
246
274
|
|
|
275
|
+
// Save all rules
|
|
276
|
+
this.$contenedor.find(".save-rules-snapshot").on("click", function (e) {
|
|
277
|
+
e.preventDefault();
|
|
278
|
+
self.takeSnapshot();
|
|
279
|
+
});
|
|
280
|
+
|
|
247
281
|
// Apply current filters to data
|
|
248
282
|
this.$contenedor.find("#apply-rules-btn").on("click", function (e) {
|
|
249
283
|
e.preventDefault();
|
|
@@ -337,7 +371,7 @@
|
|
|
337
371
|
|
|
338
372
|
// 1. Extraemos los valores únicos de la base de datos actual
|
|
339
373
|
let uniqueOptions = [...new Set(this.data.map(function (item) {
|
|
340
|
-
const val = getValueByPath(item, dataField)
|
|
374
|
+
const val = getValueByPath(item, dataField)?.toString();
|
|
341
375
|
if (val !== undefined && val !== null) {
|
|
342
376
|
return JSON.stringify({ id: val, text: val });
|
|
343
377
|
}
|