json-rules-filter 1.0.15 → 1.0.17
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/src/jquery.jsonRulesFilter.js +34 -17
package/package.json
CHANGED
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
|
|
21
21
|
// --- DEFAULT CONFIGURATION ---
|
|
22
22
|
const settings = $.extend(true, {
|
|
23
|
-
bsVersion:5,
|
|
23
|
+
bsVersion: 5,
|
|
24
24
|
filters: [
|
|
25
|
-
{ name: "Example", type: "number", data: "example", render: function(data){return data.text /*Callback to render html in options type select*/}}
|
|
25
|
+
{ name: "Example", type: "number", data: "example", render: function (data) { return data.text /*Callback to render html in options type select*/ } }
|
|
26
26
|
],
|
|
27
27
|
language: {
|
|
28
28
|
string: {
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
nGreatherThanOrEquals: "Mayor o igual que", nLowerThan: "Menor que", nLowerThanOrEquals: "Menor o igual que"
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
|
-
title: {text:"Reglas de filtrado",className:"fs-6 fw-semibold"},
|
|
37
|
+
title: { text: "Reglas de filtrado", className: "fs-6 fw-semibold" },
|
|
38
38
|
buttons: {
|
|
39
39
|
reset: { text: "Resetear", className: "fw-semibold link-danger link-offset-2 link-underline link-underline-opacity-0" },
|
|
40
|
-
dropdown: { text: "Añadir regla", className: "btn btn-secondary"},
|
|
40
|
+
dropdown: { text: "Añadir regla", className: "btn btn-secondary" },
|
|
41
41
|
apply: { text: "Aplicar regla", className: "btn btn-primary" },
|
|
42
42
|
},
|
|
43
43
|
onApply: function (filtros, datosFiltrados) { }
|
|
@@ -53,11 +53,11 @@
|
|
|
53
53
|
$contenedor: $contenedor,
|
|
54
54
|
|
|
55
55
|
// ---- Compatibility helper bs5/bs4 ------
|
|
56
|
-
bs: function(classes) {
|
|
56
|
+
bs: function (classes) {
|
|
57
57
|
if (this.settings.bsVersion === 5) return classes;
|
|
58
58
|
|
|
59
59
|
const map = {
|
|
60
|
-
'fs-6':'',
|
|
60
|
+
'fs-6': '',
|
|
61
61
|
'fw-semibold': 'font-weight-bold',
|
|
62
62
|
'fw-bold': 'font-weight-bold',
|
|
63
63
|
'link-danger': 'text-danger',
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
dataField: $el.data("field"), // JSON key path
|
|
101
101
|
dataName: $el.data("name"), // Display name
|
|
102
102
|
// Text of the selected option for labels/summary
|
|
103
|
-
optionFilterText: $el.find("option:selected").map(function(){ return $(this).text(); }).get()
|
|
103
|
+
optionFilterText: $el.find("option:selected").map(function () { return $(this).text(); }).get()
|
|
104
104
|
});
|
|
105
105
|
})
|
|
106
106
|
return rulesAplicated;
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
<div class="py-2" id="container-rules-filters"></div>
|
|
145
145
|
<div class="mt-2">
|
|
146
146
|
<div class="d-flex justify-content-start dropdown">
|
|
147
|
-
<button ${this.settings.bsVersion === 5
|
|
147
|
+
<button ${this.settings.bsVersion === 5 ? `data-bs-popper-config='{"strategy":"fixed"}'` : ''} class="${this.bs(this.settings.buttons.dropdown.className)} dropdown-toggle" type="button" ${toggleAttr}>
|
|
148
148
|
${this.settings.buttons.dropdown.text}
|
|
149
149
|
</button>
|
|
150
150
|
<div class="dropdown-menu p-2 dropdown-rules-columns" style="min-width: 300px;">
|
|
@@ -156,26 +156,42 @@
|
|
|
156
156
|
</div>
|
|
157
157
|
</div>`;
|
|
158
158
|
this.$contenedor.append(template);
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
// Event delegation and listeners
|
|
162
|
+
bindEvents: function () {
|
|
163
|
+
const self = this;
|
|
164
|
+
|
|
165
|
+
//Dropdown events
|
|
159
166
|
const $dropdown = this.$contenedor.find('.dropdown-toggle');
|
|
160
167
|
|
|
161
168
|
if (this.settings.bsVersion === 4) {
|
|
162
169
|
//BS4
|
|
163
170
|
$dropdown.dropdown({
|
|
171
|
+
display: 'static',
|
|
164
172
|
popperConfig: {
|
|
165
|
-
positionFixed: true
|
|
173
|
+
positionFixed: true,
|
|
174
|
+
modifiers: {
|
|
175
|
+
preventOverflow: {
|
|
176
|
+
boundariesElement: 'window'
|
|
177
|
+
}
|
|
178
|
+
}
|
|
166
179
|
}
|
|
167
180
|
});
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
181
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
182
|
+
//Dropdown
|
|
183
|
+
$dropdown.on('click', function (e) {
|
|
184
|
+
e.stopPropagation();
|
|
185
|
+
const $conatiner_dropdown = $(this).parent().find('.dropdown-rules-columns');
|
|
186
|
+
$(this).dropdown($conatiner_dropdown.hasClass('show') ? "hide" : "show");
|
|
187
|
+
});
|
|
188
|
+
}
|
|
174
189
|
|
|
175
190
|
// Add new rule row
|
|
176
191
|
this.$contenedor.find(".dropdown-rules-item").on("click", function (e) {
|
|
177
192
|
e.preventDefault();
|
|
178
193
|
self.addRuleRow($(this).data("column-type"), $(this).data("column-data"), $(this).data("column-name"));
|
|
194
|
+
$dropdown.dropdown("hide");
|
|
179
195
|
});
|
|
180
196
|
|
|
181
197
|
// Clear all rules
|
|
@@ -202,7 +218,7 @@
|
|
|
202
218
|
const self = this;
|
|
203
219
|
const $container = this.$contenedor.find("#container-rules-filters");
|
|
204
220
|
|
|
205
|
-
|
|
221
|
+
// Generate unique ID for the new row based on the last element
|
|
206
222
|
let id_select = 0;
|
|
207
223
|
const last_container = $contenedor.find("select[name=select-rule-option]").last();
|
|
208
224
|
if (last_container.length > 0) { id_select = last_container.data("id") + 1; }
|
|
@@ -235,7 +251,7 @@
|
|
|
235
251
|
</div>`;
|
|
236
252
|
|
|
237
253
|
$container.append(row);
|
|
238
|
-
|
|
254
|
+
// Fetch custom render function from settings
|
|
239
255
|
const render = self.settings.filters.find((e) => e.data === dataField).render;
|
|
240
256
|
this.initSelect2(id_select, type, dataField, render);
|
|
241
257
|
},
|
|
@@ -247,6 +263,7 @@
|
|
|
247
263
|
|
|
248
264
|
$select.select2({
|
|
249
265
|
width: '100%',
|
|
266
|
+
dropdownParent: this.$contenedor, // Parent render
|
|
250
267
|
escapeMarkup: function (markup) { return markup; }, // Allow HTML rendering in badges
|
|
251
268
|
templateSelection: render,
|
|
252
269
|
templateResult: render,
|
|
@@ -302,7 +319,7 @@
|
|
|
302
319
|
if (valorOriginal === undefined || valorOriginal === null) return false;
|
|
303
320
|
|
|
304
321
|
// Special logic for Multiple Select filters
|
|
305
|
-
if(regla.typeFilter === 'select'){
|
|
322
|
+
if (regla.typeFilter === 'select') {
|
|
306
323
|
const selectedValues = regla.optionFilter; // Array from Select2 multiple
|
|
307
324
|
return selectedValues.includes(valorOriginal.toString());
|
|
308
325
|
}
|