What is the best way to enable search functionality for content within an expandable slot of a data table in VuetifyJS?

I've been experimenting with the VuetifyJS/VueJS data table which includes an expand slot. How can I enable search functionality for the content within the expand slot? I attempted to wrap the content in <td></td>, but it didn't yield the desired results.

You can check out a sample on Codepen:

https://codepen.io/anon/pen/VBemRK?&editors=101
When searching for "find me", the result is always "
Your search for "find me" found no results.
".


      <v-data-table
    :headers="headers"
    :items="desserts"
    :search="search"
    item-key="name"
  >

<template slot="items" slot-scope="props">
  <tr @click="props.expanded = !props.expanded">
      <td>{{ props.item.name }}</td>
      <td class="text-xs-right">{{ props.item.calories }}</td>
      <td class="text-xs-right">{{ props.item.fat }}</td>
      <td class="text-xs-right">{{ props.item.carbs }}</td>
      <td class="text-xs-right">{{ props.item.protein }}</td>
      <td class="text-xs-right">{{ props.item.iron }}</td>
    </template>

     <template slot="expand" slot-scope="props">
  <v-card flat>
    <v-card-text><td>Peek-a-boo! Please find me too.</td></v-card-text>
  </v-card>
         </template> 

    <v-alert slot="no-results" :value="true" color="error" icon="warning">
      Your search for "{{ search }}" found no results.
    </v-alert>
  </v-data-table>

Answer №1

Implement a custom filtering solution.

To begin, define a custom filtering function:

methods: {
    customFilter(items, query) {
      return items.filter(item => JSON.stringify(item).toLowerCase().indexOf(query.toLowerCase()) !== -1)
    }
}

Next, include :custom-filter="customFilter" in the v-data-table component:

<v-data-table
    :headers="headers"
    :custom-filter="customFilter"
    :items="dataItems"
    :search="searchQuery"
    item-key="keyValue"
>

View the modified code snippet on CodePen: https://codepen.io/WisdomSky/pen/PBNvYZ

Answer №2

If you are working with Vuetify version 2 or later, make sure to utilize the custom-filter prop as it now follows a different structure.

export default {
  methods: {
    customDataTableItemsFilter(value, search, items) {
      /*
      This filter function is designed to search for individual words within the search string. It examines all object values rather than just the keys specified in the data table headers.
       */
      const wordArray = search
        .toString()
        .toLowerCase()
        .split(' ')
        .filter(x => x)
      return wordArray.every(word =>
        JSON.stringify(Object.values(items))
          .toString()
          .toLowerCase()
          .includes(word)
      )
    }
  }
}

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

What changes can I make to my method in order to utilize async/await?

Within my React application, I have implemented a post request to the server using axios: onSubmit = async (results) => { try { const response = await axios.post("http://localhost:8080/simulate/", results); this.setState({results: ...

Errors encountered while using AngularJS HTTP GET request

I have encountered an issue with my Angular Js app when attempting to retrieve json data from my web server (which is created using codeigniter). It seems that while other urls provide the expected json data response, mine does not. Here is the Angular js ...

Meteor: Locate the closest transportation option between two locations

I'm currently in the process of developing a carsharing app, and when it comes to setting up rides, I have this kind of data structure stored in my database: { "_id": "YyPpkCDhTKStGw6CL", "authorId": "W6zvbcqit4Mw6a2iK", " ...

Adding elements to a webpage dynamically using the jQuery append method

<ul> <li><a href="">not here</a></li> <li><a href="">append text only if child ul is present</a> <ul> <li><a href="">not here</a></li> <li><a href=""> ...

The anchor tags are currently not able to be disabled

I am facing an issue with disabling an anchor tag based on the status field in a response coming from the backend. Even though I have tried to debug the problem, I couldn't figure out why it's not working. Can someone provide guidance on how to r ...

Encountering an issue with compiling Angular due to a Type Inference error

interface Course { name: string; lessonCount: number; } interface Named { name: string; } let named: Named = { name: 'Placeholder Name' }; let course: Course = { name: 'Developing Apps with Angular', lessonCount: 15 }; named = ...

Learn the process of synchronously loading forms and data in Angular

Looking to synchronize the loading of data and form... Let's start by reviewing the code: ngOnInit() { if (this.data.fromCalendar) { this.singleTraining(); } }, 200); this.formControl(); } formControl() { this.gib ...

The ng-model remains empty even after the $parent has been defined

I've encountered an issue where assigning ng-model to a text area and an input does not update the models. It is mentioned that this could be due to using ng-if causing a different scope, and I should use $parent, but even that solution is not working ...

"Exploring the implementation of mute event in Audio HTML5 using JavaScript within an MVC

I am searching for an event that triggers when the mute button is pressed. The volumechange event only works when the volume is adjusted. <audio id="volumeController" onvolumechange="changeVolume()"controls> <source src="~/Sounds/be ...

Ensuring Vue.js methods are correctly configured to handle Axios asynchronous requests

My Vue.js application fetches complex data from an API using Axios and then visualizes the data. Here is a snippet of my code: { data: () => ({ data: null, loading: false, errored: false, loadingMessage: '' }), methods: ...

Selecting a particular item in a list depending on time using JavaScript, jQuery, or Angular

When working with a JSON file and binding it to list items, I have included a name/value pair in the json for each line indicating audio time, such as "time like 0, 5, 10 in seconds form". In my Cordova application, I am using a media plugin and implement ...

What is the best way to set up MVC in nodejs with express framework?

I am working on a nodejs + express project and I need help mounting controllers and views. In my app.js file, I have the following lines: var stats = require('./controllers/stats'); and app.use(stats); My controllers folder contains: stats/inde ...

How to print a Base64 encoded file with the Print.js library

I am facing an issue with printing a Base64 file. Despite my efforts, the file does not print as expected. function convertToBase64() { var selectedFile = document.getElementById("inputFile").files; if (selectedFile.length > 0) { var fi ...

What is the impact of util.inherits on the prototype chain in JavaScript?

Exploring this particular design: Function ConstrA () { EventEmitter.call(this); } util.inherits(ConstrA, EventEmitter); var obj = new ConstrA(); If util.inherits is omitted, ConstrA and obj will each establish their own distinct prototype chain. T ...

Vue 2: Avoid using Prop Object directly within template section

Query: Despite accurately passing the prop through Vue DevTools and ensuring that the router-view component has access to the necessary data in the correct format, I encounter a puzzling issue. When attempting to access any of the data properties within th ...

What is the best method for converting an ASCII JSON 3D model file into binary format?

As I delved into various webGL examples, particularly those based on Three.js, I came across a fascinating method of loading large models using a combination of ASCII and binary JSON. This technique caught my attention due to the significant reduction in f ...

Merge JavaScript function mouseup

I've been trying to combine JS functions, but it's not working as expected. Can anyone provide some suggestions for my code? $(document).ready(function(){ $(".searchs").keyup(function() { var searchbox = $(this).val(); var dataString = ...

Use the `document.getElementsByClassName` method to retrieve elements with a specific class name and then insert content between

Is it possible to select the only post with a 'selected' class and then insert a div inside or between other divs? I am currently uploading images to my website's timeline and now I am attempting to group multiple images posted on the same d ...

How can I use JavaScript or JQuery to retrieve the HTML content as a string from a specific URL?

How can I extract the URL of a link from a webpage and add it to my code without an ID for that specific link? Is there a way to search based on the content within the <a> tag? ...

Exploring the use of leaflets within LitElement

I have been working on a project involving LitElement components and I am looking to incorporate Leaflet into it. However, I am encountering difficulties with displaying the map properly. After installing Leaflet through npm in my project, I created a clas ...