json-rules-filter 1.0.0 → 1.0.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.
- package/package.json +1 -1
- package/readme.md +43 -20
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -177,28 +177,12 @@ onApply: function (rules, filteredData) {
|
|
|
177
177
|
|
|
178
178
|
## 🛠️ Métodos públicos
|
|
179
179
|
|
|
180
|
-
```javascript
|
|
181
|
-
$("#miFiltro").jsonRulesFilter("nombreMetodo", parametros);
|
|
182
|
-
```
|
|
183
|
-
|
|
184
180
|
### updateData
|
|
185
181
|
|
|
186
182
|
```javascript
|
|
187
183
|
$("#miFiltro").jsonRulesFilter("updateData", nuevosDatos);
|
|
188
184
|
```
|
|
189
185
|
|
|
190
|
-
### getAplicatedRules
|
|
191
|
-
|
|
192
|
-
```javascript
|
|
193
|
-
const reglas = $("#miFiltro").jsonRulesFilter("getAplicatedRules");
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
### reset
|
|
197
|
-
|
|
198
|
-
```javascript
|
|
199
|
-
$("#miFiltro").jsonRulesFilter("reset");
|
|
200
|
-
```
|
|
201
|
-
|
|
202
186
|
---
|
|
203
187
|
|
|
204
188
|
## 🧪 Ejemplo completo
|
|
@@ -210,17 +194,56 @@ const empleados = [
|
|
|
210
194
|
{ name: "Pedro", total: 220, cargo: "Developer" }
|
|
211
195
|
];
|
|
212
196
|
|
|
213
|
-
$("#
|
|
197
|
+
$("#container-rules").jsonRulesFilter(empleados, {
|
|
214
198
|
filters: [
|
|
215
199
|
{ name: "Nombre", type: "text", data: "name" },
|
|
216
200
|
{ name: "Total", type: "number", data: "total" },
|
|
217
|
-
{ name: "Cargo", type: "select", data: "cargo"
|
|
201
|
+
{ name: "Cargo", type: "select", data: "cargo",function(data){
|
|
202
|
+
return`<span class="badge text-bg-success">${data}</span>`;
|
|
203
|
+
}}
|
|
218
204
|
],
|
|
219
|
-
onApply: function (rules, results) {
|
|
220
|
-
|
|
205
|
+
onApply: function (rules, results) {
|
|
206
|
+
$("#container-rules-collapse").empty();
|
|
207
|
+
|
|
208
|
+
//generamos indicador budge para contenedor de filtros
|
|
209
|
+
$.each(reglas, function (index, element) {
|
|
210
|
+
|
|
211
|
+
let text = `${element.dataName} ${element.optionFilterText.toLowerCase()} ${element.searchValue}`;
|
|
212
|
+
|
|
213
|
+
if (element.typeFilter === 'select') {
|
|
214
|
+
text = `${element.dataName} en (${element.optionFilter.join(", ").toLowerCase()})`
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const budge =`<span class="badge rounded-pill text-bg-primary ml-1">${text}</span>`;
|
|
218
|
+
|
|
219
|
+
$("#container-rules-collapse").append(budge);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
$("#num-filters").html(reglas.length);
|
|
221
223
|
}
|
|
222
224
|
});
|
|
223
225
|
```
|
|
226
|
+
```html
|
|
227
|
+
<div class="max-w-8xl mx-auto sm:px-6 px-8">
|
|
228
|
+
<div class="mt-3 bg-white overflow-hidden shadow-sm border border-secondary rounded-xl px-3 py-2">
|
|
229
|
+
<div id="container-rules" class="collapse py-2 px-2">
|
|
230
|
+
|
|
231
|
+
</div>
|
|
232
|
+
<div class="d-flex justify-content-between py-2 pe-2">
|
|
233
|
+
<div class="pl-2 d-flex justify-content-start">
|
|
234
|
+
<span class="fw-semibold">Filtros activos:</span>
|
|
235
|
+
<div id="container-rules-collapse"></div>
|
|
236
|
+
</div>
|
|
237
|
+
<a class="link-dark position-relative" data-bs-toggle="collapse" href="#container-rules"
|
|
238
|
+
role="button">
|
|
239
|
+
<i class="fa-solid fa-filter"></i>
|
|
240
|
+
<span id="num-filters"
|
|
241
|
+
class="position-absolute top-0 start-100 translate-middle badge rounded-pill text-bg-secondary">0</span>
|
|
242
|
+
</a>
|
|
243
|
+
</div>
|
|
244
|
+
</div>
|
|
245
|
+
</div>
|
|
246
|
+
```
|
|
224
247
|
|
|
225
248
|
---
|
|
226
249
|
|