I'm working on implementing a search/filter functionality for a data table. Currently, I have managed to filter only one element in the array. Here is the array structure;
dataArray: [
{ date: "12.02.2021", time: "Aaa", level: '1111', service: 'Zzzz', description: '124-362' },
{ date: "13.02.2021", time: "Bbbb", level: '2222', service: 'Yyyyy', description: '748-987' },
{ date: "14.02.2021", time: "Cccc", level: '3333', service: 'Xxxxx', description: '012-365' },
{ date: "15.02.2021", time: "Dddd", level: '4444', service: 'Qqqqq', description: '271-016' },
{ date: "16.02.2021", time: "Eeee", level: '5555', service: 'Tttt', description: '341-222' },
{ date: "17.02.2021", time: "Ffff", level: '6666', service: 'Uuuu', description: '932-324' },
{ date: "18.02.2021", time: "Gggg", level: '7777', service: 'Vvvvv', description: '459-974' },
{ date: "19.02.2021", time: "Hhhh", level: '8888', service: 'Wwwww', description: '224-569' },
{ date: "20.02.2021", time: "Jjjj", level: '9999', service: 'Mmmm', description: '617-619' },
{ date: "21.02.2021", time: "Kkkk", level: '10101010', service: 'Nnnnn', description: '825-379' },
],
Below is the HTML structure used for displaying the filtered items;
<tr v-for="(dataArray, i) in filteredItems" :key="i">
<p class="table-iterator">{{i--}}</p>
<td class="table-row text-left">{{connectivityLogs.date}}</td>
<td class="table-row text-center">{{connectivityLogs.time}}</td>
<td class="table-row text-center">{{connectivityLogs.level}}</td>
<td class="table-row text-center">{{connectivityLogs.service}}</td>
<td class="table-row text-right">{{connectivityLogs.description}}</td>
</tr>
Above the table, there is an input field
<input type="text" v-model="search">
where the search
variable has been declared in the Vue script's data
section.
Finally, here is how filtering based on only the 'time' element is implemented using a computed property;
computed: {
filteredItems(){
return this.dataArray.filter(dataArray => {
return dataArray.time.toLowerCase().indexOf(this.search.toLowerCase()) > -1
})
}
}
I need assistance with extending this filtering operation to apply to all elements rather than just 'time'. How can I achieve this?