Skip to content

Commit 4e28726

Browse files
authored
fix(table): filtered event not firing when filter cleared (issue bootstrap-vue#859) (bootstrap-vue#860)
* fix(table): filtered event not firing when filter cleared (issue bootstrap-vue#859) Addresses issue bootstrap-vue#859 in v0.x branch * Update table.vue
1 parent 4890f57 commit 4e28726

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lib/components/table.vue

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@
124124
return {
125125
localSortBy: this.sortBy || '',
126126
localSortDesc: this.sortDesc || false,
127-
localItems: []
127+
localItems: [],
128+
// Note: filteredItems only used to determine if # of items changed
129+
filteredItems: []
128130
};
129131
},
130132
props: {
@@ -263,6 +265,12 @@
263265
this._providerUpdate();
264266
}
265267
},
268+
filteredItems(newVal, oldVal) {
269+
if (!this.providerFiltering && newVal.length !== oldVal.length) {
270+
// Emit a filtered notification event, as number of filtered items has changed
271+
this.$emit('filtered', newVal);
272+
}
273+
},
266274
sortDesc(newVal, oldVal) {
267275
if (newVal === this.localSortDesc) {
268276
return;
@@ -383,9 +391,6 @@
383391
384392
// Apply local filter
385393
if (filter && !this.providerFiltering) {
386-
// Number of items before filtering
387-
const numOriginalItems = items.length;
388-
389394
if (filter instanceof Function) {
390395
items = items.filter(filter);
391396
} else {
@@ -401,11 +406,10 @@
401406
return test;
402407
});
403408
}
404-
405-
if (numOriginalItems !== items.length) {
406-
// Emit a filtered notification event, as number of items has changed
407-
this.$emit('filtered', items);
408-
}
409+
}
410+
if (!this.providerFiltering) {
411+
// Make a local copy of filtered items to trigger filtered event
412+
this.filteredItems = items.slice();
409413
}
410414
411415
// Apply local Sort

0 commit comments

Comments
 (0)