New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
b-table: filter
as object not reactive anymore when using items provider
#4065
b-table: filter
as object not reactive anymore when using items provider
#4065
Comments
Do you use a provider as items? Is it being called twice? I'm having the same issue. Added a test on #4067 |
@caiquecastro it is possible that providers may be called twice (initially) if you don't have a field definition provided (so b-table can lookup the field names) |
@FabianAlbrecht there is a mistake in your template. You are passing a string to the <template>
<div>
<b-form-input v-model="filterObject.filterText" />
<b-table :items="items" fields='name' :filter="filterObject" :filter-function="filterFunction" />
</div>
</template> You need to pass an array of field names (or an array of fiend definition objects): <template>
<div>
<b-form-input v-model="filterObject.filterText" />
<b-table :items="items" :fields="['name']" :filter="filterObject" :filter-function="filterFunction" />
</div>
</template> Making the above change, all is working fine for me. |
@tmorehouse You are right, that i made a mistake here. |
If I type in |
Unfortunately not for me. Maybe there is a problem with the Sandbox? When I open your sandbox (https://codesandbox.io/s/quizzical-haslett-9jfr7) it shows the following error in the console, because there is a colon missing in front of the 'fields' prop: Is it possible that it is not the current version of your code? |
I might not have saved it when forking.... |
When using a computed prop to return the filter object (which generates a new object whenever the criteria changes) it works... But when passing the same object reference of which properties inside change, it doesn't appear to be detecting the change. May need to make the |
PR #4068 fixes the issue... and will be available in v2.0.1 later this week. As a workaround, you can use a computed prop to generate the filter object (which creates a new object when the criteria changes: <template>
<div>
<b-form-input v-model="filterObject.filterText" />
<b-table
:items="items"
:fields="['name']"
:filter="computedFilterObject"
:filter-function="filterFunction"
/>
</div>
</template>
<script>
export default {
data() {
return {
items: [{ name: "Item 1" }, { name: "Item 2" }],
filterObject: { filterText: '' }
}
},
computed: {
computedFilterObject() {
return {
filterText: this.filterObject.filterText
}
}
},
methods: {
filterFunction(item, filterObject) {
console.log(new Date(), item.name, filterObject.filterText);
return item.name.toLowerCase().includes(filterObject.filterText);
}
}
}
</script> |
Thanks for fixing the issue. Your workaround works perfectly. |
@FabianAlbrecht the fix will be in v2.0.1, which would hopefully be released later this week. |
filter
as object not reactive anymore when using items provider
Describe the bug
When you pass a filter-object to b-table the filter-function will not be triggered when the properties of the object change. (No reactivity)
This happens since version 2.0.0.
Steps to reproduce the bug
Expected behavior
The Table is filtered according to the entered value
Versions
Libraries:
Environment:
Demo link
https://codesandbox.io/s/gallant-curie-dkrsc
The text was updated successfully, but these errors were encountered: