Displaying a table using Vue.js to showcase filtered data fetched with Axios

I have been struggling to find a solution for displaying filtered results in my table using Vue.js and Axios. While I am able to filter the results with an if statement, the issue arises when exporting the data as it includes unfiltered results as well. Currently, I am attempting to filter the Axios response, but the table continues to display all the data from the response. Any alternative methods or suggestions on how to achieve filtered results other than using filter would be greatly appreciated.

Here is my table:

<v-data-table
                  :headers="headers1"
                  :items="new_users"
                  :rows-per-page-items="rowsPerPage"
                  :search="search"
                  :loading="true"
                  class="elevation-1"
                  item-key="id"
                >

                <template slot='no-data'>
                    <v-progress-linear slot='progress' indeterminate></v-progress-linear>
                </template>

                  <template
                    slot="items" slot-scope="props">
                    <!-- v-if="props.item.profile_complete === 0"> -->
                      <td>{{ props.item.gender }}</td>
                      <td>{{ props.item.msisdn }}</td>
                      <td>{{ props.item.email }}</td>
                      <td>{{ props.item.profile_complete }}</td>

Computed property :

computed: {
    filteredList() {
      let self = this;
      this.new_users = this.users_ttl.filter(item => item.profile_complete === 0);
    }
  },

Method

getUsers () {
      axios.get('users')
        .then((response) => {
          this.users_ttl = response.data.data
          this.loopT(response.data.links.next)
          this.isLoading = false
        })
        .catch((error) => {
          console.log(error)
          this.error = true

        })
    },

Answer №1

Your current computed property is not being utilized and does not return a value, leading to data mutation within it, which is considered poor practice.

Consider replacing your existing computed property with the following:

computed: {
    filteredList() {
      return this.users_ttl.filter(item => item.profile_complete === 0);
    }
  },

You can then utilize the filtered list in your template like this:

<v-data-table
  ...
  :items="filteredList"
  ...
>
...

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

Configuration file included in Node.js package for distribution

Someone recommended incorporating Continuous Integration for a pre-existing application (FrontEnd: Node.js - BackEnd: .Net API). At the moment, the API endpoints are hardwired in the .js files which become minified after being built using webpack. I plan ...

What is the best way to combine two JSON objects?

Item A: var item1 = { "roleid": "001", "techid": "001", "role": "WEB DEVELOPER", "tech": "JAVASCRIPT", "experience": [], "certifications": [], "gender": ["Male"], "awards": [], "min_experience_years": "4", "max_expe ...

What is the best way to fetch all records where the property matches a portion of the specified parameter?

Below is the Mongoose Schema that I currently have var People= new Schema({ firstName: String, alias: [String] }); I am trying to find a method to retrieve all documents where one of the alias strings matches or is contained in some way withi ...

How is it possible that Firebase is displaying undefined in my component, yet I can clearly view the object in console.log after reading from my database?

Using Next.js and Typescript in my project. I recently created a custom hook to read data from the firebase realtime database, which returns an array of objects. However, I am facing an issue where I am unable to pass this array to my component successful ...

Adding a color picker to a Kendo Grid

I am working with a kendo grid that has inline editing feature. I am looking to add a kendo colorpicker to a specific column. Is there a way to display the selected color even when the row is not in the editing mode? Does anyone have an example of how to ...

Update the URL and parse the data in a Backbone collection

For the purpose of development, I am looking to replace the collection with fake JSON results either from a JSON variable or a JSON file. However, I encountered an error when attempting to do so using url http://jsfiddle.net/qhoc/uZhM8/ GET http://fiddle ...

Button to close Jquery Dialog

I've set up a custom alert UI using jQuery UI, but I'm having trouble getting the close button to work properly. Here's my code snippet where I'm trying to override the default alert() function with jQuery UI dialog as described in this ...

Check the validity of multiple selection groups using JavaScript

Here is the link to my JS Fiddle: http://jsfiddle.net/m4tyC/ I am working with multiple select tags and need to validate them upon submission. For example, at least one of size1, color1, or Qty1 must be selected in the first group. If one item is selected ...

Sharing a variable between two methods in a controller.js file using JavaScript with Express in NodeJS

I have a MongoDB, Express, Angular, Node application. I'm attempting to pass a variable that is the result of a method in one file to another method in a separate file. During a series of user actions, it triggers a method exports.test inside the tes ...

Mastering regular expressions in TypeScript

My goal is to perform linting on staged files that are either .ts or .tsx and located within the src folder. I am aware that for selecting all js files one can use "*.js": [--list of commands--] inside the lint staged property. I'm curious to learn m ...

Is there a way to use jQuery to centrally align the accordion item that I have chosen?

My attempts to use `this.scrollIntoView({behavior: "smooth"}) were yielding inconsistent results in terms of where the selected item would land on the page. I believe I might need to utilize scrollTop(), but as someone who is new to jQuery, I am ...

Issues with debuggers in Chrome and Firefox with AngularJS are causing frustration for developers

Currently, I am in the process of developing a hybrid application that combines AngularJS with Angular 8. As part of my testing procedure, I am attempting to debug the application. However, I have encountered an issue where the debuggers function properly ...

Angular Js powered admin control panel

Explore the SB Admin Angular by Start Angular My current project involves setting up an admin dashboard on a Windows system. However, I have encountered some issues during the installation process using npm install An error message can be found here ...

Enhancing nested mongoose arrays by a particular value for updates

In my mongoose schema, I have an array that contains items and another array. var mongoose = require('mongoose'); var Schema = mongoose.Schema; var CompanySchema = new Schema({ dateCreated: { type: Date, default: Date.now }, ownerId: { typ ...

Executing a Component function within an "inline-template" in VueJS

VueJS version 1.9.0 app.js require('./bootstrap'); window.Vue = require('vue'); Vue.component('mapbox', require('./components/mapbox.js')); const app = new Vue({ el: '#app' }); components/mapbox.js ...

Is there a different way to retrieve the tag name of an element besides using

Currently, I am dealing with an outdated version (Chromium 25) of chromium. My goal is to utilize the tagName method in order to retrieve the name of the specific HTML tag being used. While I am aware that Element.tagName functions for versions 43 and ab ...

Version incompatibility issue with Vue 3 package

Currently, I am in the process of updating a package that I created to work with vue 3. However, I have encountered an issue with vue-template-compiler. I attempted to follow a similar post that addressed a comparable problem, but unfortunately, the solut ...

Possible solution to address the issue: xhr.js:178 encountered a 403 error when attempting to access https://www.googleapis.com/youtube/v3/search?q=Tesla

Encountering this console error: xhr.js:178 GET https://www.googleapis.com/youtube/v3/search?q=river 403 A specific component was designed to utilize the API at a later point: const KEY = "mykeyas23d2sdffa12sasd12dfasdfasdfasdf"; export default ...

Is there a way to load an image onto the ngx-image-cropper without triggering the imageChangedEvent event?

My latest project involved creating a custom cropper using ngx-image-cropper, which allows for cropping and rotating images. For the sprint demo, I needed the images to be displayed as soon as the application loads without having to trigger the fileChangeE ...

Destructuring array in React using Javascript

I'm currently exploring ReactJS and I'm facing a dilemma in understanding the destructuring process in the code snippet below: const IngredientsList = ({ list }) => React.createElement('ul', null, list.map((ingredient, i ...