Using Vue to create a search feature within a table

I am facing an issue with the search functionality in my Vue template. Despite implementing the necessary code, the search feature is not working as expected.

<input type="text" class="dv-header-input" v-model="query.search_input"
  @keyup.enter="fetchRecords()">

Here is the table structure:

<tr v-for="row in filteredRow">
    <td v-for="(value, key) in row">{{value}}</td>
</tr>

And this is the relevant JavaScript code:

export default {
    props: [
      'source', 
      'title',
    ],
    data() {
      return {
        model: { data: [] },
        columns: {},
        query: {
          search_input: ''
        },
      }
    },
    created() {
      this.fetchRecords()
    },
    methods: {
      fetchRecords() {
        var vm = this
        // This is not the original API call
        axios.get(/get/Details)
          .then(function(response) {
            Vue.set(vm.$data, 'model', response.data.model)
            Vue.set(vm.$data, 'columns', response.data.columns)
          })
          .catch(function(response) {
            console.log(response)
          })
      }
    },
    computed: {
      filteredRow: function(){
        return this.model.data.filter((row) => {
          for(var key in row){
            return String(row[key]).indexOf(this.query.search_input);
          }
        });
      }
    }
  }

While trying to debug, I used

console.log(String(row[key]).indexOf(this.query.search_input))'
within filteredRow, which returned 30 times 0. I'm unsure about what I might have missed and would appreciate suggestions on the best approach to resolve this.

Answer №1

Not a chance that for loop will go beyond the initial key in the row. The objective is to only return true if you locate the specified string:

  filteredRow: function(){
    return this.model.data.filter((row) => {
      for(var key in row){
        if(String(row[key]).indexOf(this.query.search_input) !== -1){
          return true;
        }
      }
      return false;
    });
  }

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

Discovering the process of eliminating the greatest and second greatest elements from an array in C

The given task is coded in Keil, which is an IDE for C. unsigned short data[100] = { 58473, 33594, 38638, 26741, 13018, 29262, 16377, 12354, 46079, 57240, 48949, 34054, 16212, 58485, 6198, 38678, 22525, 51012, 43489, 8861, 54291, 21524, 7166, 22698, 39899 ...

How can I trigger the execution of textarea HTML code with an onClick event using JavaScript?

When my fingers are lifted from the keyboard, some code will be automatically executed. I want to trigger this function when I click a button (onclick) instead of using onkeyup. <div id="result"></div> <textarea ...

Issues with monitoring multi-touch gesture events using Hammer JS

Can anyone figure out why this code, which utilizes hammer.js for multi-touch gesture events, is not functioning as expected? This code closely resembles one of the examples on Hammer's documentation. Despite setting up swipe events on specific elem ...

Is there a way to assign a specific value to a particular location within an array using a method?

I am currently working on developing a method that will insert a specified value at a specific location within an array. Here is the code I have so far. The "increase" function is designed to double the length of the array store. While the increase funct ...

Finding a character within a string and performing a comparison in the C programming language

I encountered an issue that I suspect is a segfault when trying to access a specific element of a string. My goal is to identify the letter at the end of 'longitude' and determine if it's a 'W'. However, the program crashes before ...

Using the foreach loop within the Alert.alert function in React Native

function displayModal(modalarray) { return Alert.alert( "Modal Title", "Alert Message", [ modalarray.forEach(element => { "{text: element, onPress: () => console.log('button press)},"; }) ], ...

Efficient methods for transferring information between a main and pop-up page within angularjs

On my webpage, I have a button that opens a popup page. I need to figure out a way to transfer json data from the main page to the popup page. These two pages are running separate angular applications. Once the data is transferred, it will be updated base ...

What are some ways to streamline this D3 script?

My CSV data displays pass rates by organisation for different years: org,org_cat,2004_passed,2004_total,2005_passed,2005_total,2006_passed,2006_total GSK,industry,35,100,45,100,55,100 I am using D3 and aiming to create a dictionary of organisations struc ...

Try out the Jquery Chosen plugin, which allows you to select multiple instances of the same

I am currently using the chosen plugin to create multiple select input fields. You can view an example of this in action by following this link: By default, the plugin disables an option if it has already been selected. For instance, in the provided examp ...

How does the Angular2-all.umd.js compare to the angular2.js file?

Currently, Angular 2 is in its 13th beta phase. I came across https://code.angularjs.org/2.0.0-beta.13/ and noticed that there are two different versions of Angular2 available: angular2-all.umd.js angular2.js What distinguishes these two versions from ...

Leverage the power of integrating Power BI with Javascript to easily retrieve an

I have embarked on a mission to integrate PowerBI into my web application. Below is the code snippet that I have implemented: window.config = { instance: 'https://login.microsoftonline.com/', tenant: 'common', //COMMON OR YOU ...

I'm encountering some issues with routing within Node.js and Express framework

I have developed a single page application (SPA) using React framework. Currently, I am working on creating an API with Express in Node.js for my app. Below is the code snippet of my server: const express = require('express'); const app = expr ...

Populating an array with values obtained from various curl requests

I am currently utilizing the php-curl-class library and attempting to generate an array of URLs from JSON responses that correspond to a specific error code in my coding. However, my current method using array_push is resulting in all URLs being duplicated ...

Error: jQuery Validation not triggering in Bootstrap modal window

My attempts to use jQuery Validation for form validation inside a modal have hit a dead end. The validation doesn't trigger at all, not even an error message is displayed. Upon debugging, a warning emerged: No elements selected for validation; retu ...

Transforming a JSON string into a Java array

Here is some JSON code representing an array: $info=array(); while($row = mysql_fetch_array($result,MYSQL_ASSOC)){ array_push($info,$row); } $info; $result_final->lugares_cercanos = $info; Display this data: {"logstatus":"1","lugares_cercanos":[{"n ...

Is there a similar concept to "Symbol.iterator" for the object spread syntax { ...obj } in JavaScript?

One symbol that is widely recognized is Symbol.iterator. When this symbol is defined as a generator function property on an object, it enables the object to be utilized in a [...object] syntax. For example, you can do something like this: const newArray = ...

The significance of 'content' within the tailwind configuration file

In my Nuxt app, I recently encountered a warning related to changes in the purge/content options in Tailwind CSS v3.0. Despite updating the purge option to content or leaving it as is, the warning persisted without any visible impact. From what I gather, ...

MVC Controller and JavaScript Ajax Call necessitate authentication for communication

In my ASP.NET MVC application, I am utilizing AJAX calls from the Client Page using AngularJS service to perform CRUD operations through Controller Action methods. While I have implemented ASP.NET form authentication for my MVC Pages, I am now looking to ...

The mtree script in external JavaScript is failing to function properly after dynamically inserting elements using jQuery

Here are the images showing a list of data that appears in all rows after the page loads. However, when I add a row using jQuery, the data does not show up. Please refer to image 2. Image 1 https://i.sstatic.net/xzn2c.png Image 2 https://i.sstatic.net/ ...

Is there a way for me to showcase the latitude and longitude retrieved from JSON data on a Google Map using modals for each search result in Vue.js?

After receiving JSON data with search results, each containing latitude and longitude coordinates, I am attempting to display markers on a Google map modal when clicking "View Map". However, the code I'm using is not producing the desired outcome. Th ...