The result of filtering multiple data using checkboxes in Vuetify is not displaying as expected

I am currently working on developing a straightforward task scheduler that includes filtering options using checkboxes.

Below is the snippet from my vue file:

Within my templates section,

<fieldset>
    <legend>TASK STATUS</legend>
    <span v-for="(item, index) in checkboxObj" :key="index">
        <input type="checkbox" v-model="task" :value=item.value>
        {{ item.name }}
    </span>
</fieldset>
<v-simple-table>
    <thead>
        <tr>
            <th>TASK</th>
            <th>STATUS</th>
        </tr>
    </thead>
    <tbody>
        <tr v-for="(data, index) in filteredData" :key="index">
            <td>{{ data.task }}</td>
            <td>{{ data.status }}</td>
        </tr>
    </tbody>
</v-simple-table>

In my data setup,

data(){
    return{
        recordList:[
            {task:'Cleaning Garage',status:'Due Today'},
            {task:'Checking Tools',status:'Overdue'},
            {task:'Repair Bikes',status:'Due Tomorrow'}
        ],
        task:[],
        checkboxObj: [
            {name:'OVERDUE',value:'Overdue'},
            {name:'DUE TODAY',value:'Due Today'},
            {name:'DUE TOMORROW',value:'Due Tomorrow'}
        ]
    }
}

Additionally, I have implemented this computed function:

computed:{
    filteredData() {
        if(this.task){
            for(let i = 0; i < this.task.length; i++){
                return this.recordList.filter((item) => {
                    return item.status.toUpperCase().includes(this.task[i].toString().toUpperCase())
                })
            }
        }else{
            return this.recordList
        }
    }
}

My goal is to display the status results whenever a checkbox is checked. Multiple checkboxes can be selected for combined filtering purposes, resulting in an output similar to the following example images:

ORIGINAL IMAGE https://i.sstatic.net/tqR2r.png

DESIRED OUTPUT https://i.sstatic.net/PnNWC.png

Answer №1

To enhance the computed property, make the following adjustments:

computed:
{
  modifiedStatuses()
  {
    return this.tasks.map(task => task.toLowerCase());
  },
  refinedData() 
  {
    return this.modifiedStatuses.length > 0 
      ? this.dataSet.filter(entry => this.modifiedStatuses.includes(entry.state.toLowerCase()))
      : this.dataSet;
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is one round the limit for my JavaScript image slider?

After studying the JavaScript Chapter on W3Schools, I attempted to create an image slider. Initially, everything worked perfectly for the first cycle. For instance, when I clicked the next button, the slides continued to slide until the end of the slidesho ...

Discovering a way to monitor keyup and keydown occurrences in JavaScript on an iPhone

Looking to track keyup/keydown events in JavaScript on iPhone browsers. My goal is to automatically move the focus to the next form element after the user has inputted the maximum number of characters in a text box. ...

Error encountered in React and Redux: Unable to read properties of undefined (specifically 'region')

Whenever a user clicks on edit, I am fetching data (an object) into a redux state and displaying it in a textarea. Here is the code snippet: const regionData = useSelector((state) => state.myReducer.userDetailList.region); The problem arises when this ...

The system is unable to interpret the symbol property 'Symbol(Symbol.iterator)' because it is not defined

I have created a custom .any() method for Array objects to loop through an array and check if any item passes a specified function: Array.prototype.any = (comparator) => { for(let item of this){ if(comparator(item)){ return true ...

Issues with the functionality of the map method in Javascript arrays

I have integrated Laravel and Vue.js to develop a chat application. To secure my response in Laravel, I implemented encryption to prevent unauthorized access from the console: public function get() { $contacts = User::where('id', '!=&ap ...

Troubleshooting CSS override issues when swapping components in ReactJS

Access.js import React from 'react' export default class Access extends React.Component { componentWillMount(){ import ('./styles/access_page.css'); } .... <Link to="/new-account">Sign Up</Link> } Cr ...

The autofill ajax script is unable to populate dynamically added rows

As a newcomer to programming, I am trying to create a table that allows users to add new rows by clicking a button. Each row should have a field for inputting an ID which corresponds to some predefined numbers in another table, and then the other field sho ...

Finding MongoDB data using an Express route and displaying it in a Jade template

Is there a way to retrieve data from MongoDB using an express route and display it in a jade template? Below is the code snippet of my express route (express version 2.5.8): app.get('/showData',function(req,res){ db.collection('comme ...

Having trouble rendering the React app; encountered an error: JSX contents are unterminated

I am currently facing an issue while trying to fetch data from an API in React using Axios. How can I ensure that useEffect functions properly? My objective is to create a page by fetching data from an API in React through Axios. I have designed a compon ...

Utilizing recorder.js to incorporate audio recording functionality into web2py

I am currently working on a web application where I need to integrate the recorder.js file for audio recording functionality. However, I am facing issues in implementing it within the web2py framework. Can you provide detailed guidance on how to utilize th ...

Creating a harmonious relationship between a generator using recursion and promises

In Elasticsearch, it's feasible to make a "Scrolling" request. This method involves keeping a cursor open and retrieving large chunks of data gradually. Demo code is available for reference. The provided code uses callbacks and recursion to fetch dat ...

Why does the fillText() method in HTML5 Canvas erase everything after using the clearRect() method?

Whenever I use the writeTextToCanvas method before the clearCanvas method, everything works perfectly. However, if I call the clearCanvas method first and then writeTextToCanvas, the drawing functions work fine after clearing the canvas but the fillText fu ...

Using React hooks and Typescript: I was expecting to see an assignment or function call, but instead, an expression was

After working as a React developer for quite some time, my workplace recently introduced Typescript, which I am still getting familiar with. I implemented a custom hook for managing cookies, but the function it returns is generating an error. Here's ...

Creating a Webgrid in MVC and integrating it with a custom class in AngularJS

Hey there, I'm a beginner when it comes to AngularJS and I'm looking to bind the webgrid within the method of AngularJS. $scope.SaveDetails = function () { debugger; var UserID = '@Session["ID"]'; ...

Adaptively linking to the property of a deeply nested object

Attempting to bind to a property of a nested object using [(ngModel)], but facing the challenge that the path to the property is dynamically set. Consider the following three classes: class A { p1: C constructor() { p1 = new C("A") } } class B { p2: ...

What is the process for creating a new element and utilizing its reference to add child elements in React?

I've been struggling to create an HTML element in a parent component in React, and then access that component's div from a child component in order to add new elements to it. Despite multiple attempts, I can't seem to resolve the issue of p ...

Sorting nested table rows in vueJS is an essential feature to enhance

I am working with a json object list (carriers) that looks like this: https://i.stack.imgur.com/0FAKw.png Within my *.vue file, I am rendering this using the following code: <tr v-for="carrier in this.carriers"> <td>{{ carrier.id ...

Is it recommended for the main, module, and browser properties in package.json to reference the minified version or the source

When developing a JavaScript library, it is important to consider the structure in which it will be published. This typically includes various bundles such as CJS, ESM, and UMD, each with their own source, minified, and map files. my-package\ dist& ...

Issue with AngularJS causing HTML input field to limit the display to only three digits

Whenever I input a number with 4 digits or more (excluding decimals) into the designated box, it mysteriously disappears once I click away (blur). Could it be due to the currency filter causing this issue? Even though the model retains the value when logg ...

Establishing a small boutique utilizing Vue.observable for property getters

I am currently importing the createStore function into a store.js file and passing an object with state properties and mutation functions as an argument, which is working well. createStore.js import Vue from 'vue' function createStore({ state, ...