-
Notifications
You must be signed in to change notification settings - Fork 22
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
Custom cell component with input not re-rendering on search filter #91
Comments
Hello, thanks for the question. I could reproduce the behavior, but this is neither a issue with VueDataTable or VueJS. This is expected behavior due to how VueJS works under the hood and Vue was designed to work this way. Let me explain:
What is happening is the following:
What you can do is something like this: <template>
<input type="text" :value="job" @onChange="handleChange" :placeholder="'Please enter a job'" />
</template>
<script>
export default {
props: {
data: {
type: Object,
default: () => {},
},
},
computed: {
job() {
return this.data.job
}
},
methods: {
handleChange(e) {
e.preventDefault();
const value = e.target.value;
this.$emit('userEvent', { id: this.data.id, job: value });
}
}
};
</script> Then, in <template>
<vue-data-table :params="params2" @userEvent="updateUser" />
</template>
<script>
/**/
methods: {
updateUser(payload) {
const { id, job } = payload
const index = this.data.findIndex(u => u.id === id)
if (index === -1) throw new Error ("User not found")
const newUser = {... this.data[index], job };
axios.post(`/user/${id}`, newUser).then(response => {
const updatedUser = response.data
this.data.slice(index, 1, updatedUser)
})
}
}
/**/
</script> Please, take a look at the If you have more questions, feel free to ask. |
@uwla I think you misunderstand the issue when you say
According to the problem description, the job component input is not being changed. The only input being changed is vue-data-table's search input, which filters the table, but then does not pass the correct |
@chringel21 and @Yoduh I think now I understand what the reported problem is, from your descriptions. But I cannot reproduce it. Look at the GIF below, which everything seems to be fine: What is happening on your side? Can you show me some GIF or video? |
Thanks @uwla for your response! There were three things I was doing in a different was
After switching to |
Good it worked! @chringel21, I would also like to point out that the search filter only searches for normal columns by default. So, by default, if you search for "Engineer", it will display nothing instead of the rows whose job column has "Engineer" because this column uses custom component. It will only search for a column with custom component if you provide a params = {
data: users,
columns: [
{ key: "name" },
{ key: "email" },
{
key: "permissions",
searchable: true,
searchFunction: (search, row) => {
search = search.toLowerCase()
return row.permissions.some(permission =>
permission.toLowerCase().includes(search))
},
}
]
} |
Hi @uwla
I am currently experiencing an issue where the value of input fields in custom cell components is not correctly re-rendering when filtering via search.
I've created a Codesandbox example to show what I mean.
Notice that when filtering via search, the values of the input fields in column 3 don't update or re-render. The first entry has a job of 'Recreational Therapist', but when filtering for 'Corine', it still has the value of 'Recreational Therapist'.
Is this an issue with VDT or am I doing something wrong here regarding Vue?
Thanks in advance!
The text was updated successfully, but these errors were encountered: