Ways to detect scrolling activity on the v-data-table module?

Are you looking for a way to detect scrolling events on the v-data-table component in Vuetify framework?

I am referring to the scenario where the table has a fixed height, causing the table body to scroll.

<v-data-table
  fixed-header
  :height=400
  :headers="headers"
  :items="desserts"
  item-key="name"
  disable-pagination
  hide-default-footer
></v-data-table>

Check out this CodePen example

Answer №1

To access the table DOM element after Vue has been mounted, simply refer to it using "this" keyword and proceed from there. Take a look at the mounted hook provided below for reference.

<template lang="html">
  <div class="graph-content">
    <v-data-table v-show="topArtistUplifts.length" id="topUpliftTable" class="data-table-custom"
      :headers="tableHeaders" :items="topArtistUplifts" fixed-header :height="tableHeight"
      :items-per-page="-1" hide-default-footer :mobile-breakpoint="0">

      <template v-slot:item.artist_name="{ item }">
        <span>
          <router-link :to="{ name: 'Artist', query: { artistId: item.artist_id, ...linkQuery }}"
            class="artist-link inline">
              {{ item.artist_name }}
          </router-link>
        </span>
      </template>
      <template v-slot:item.absolute_number="{ item }">
        <span>+{{ getAbbreviatedNum(item.absolute_number) }}</span>
      </template>
      <template v-slot:item.relative_number="{ item }">
        <span :class="percentChangeStyle(item.relative_number * 100)">{{ percentChangeFormat((item.relative_number * 100).toFixed(2)) }}</span>
      </template>
    </v-data-table>
    <div class="no-notifs full-height" v-show="!topArtistUplifts.length">
      No uplift to report yet – please check back soon.
    </div>
    <Loader v-if="updating.topArtistUplifts" :height="50"/>
  </div>
</template>

<script>
methods: {
  handleUpliftScroll(e) {
    console.log('yoooo i'm a table scroll event: ', e)
  },
},
mounted() {
  const tableWrapper = this.$el.children[0].children[0]
  tableWrapper.addEventListener('scroll', this.handleUpliftScroll)
}
</script>

Answer №2

Check out this code snippet:

const app = new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data() {
    return {
      desserts: Array.from({ length: 5000 }).map((v, k) => ({
          name: `#${k}`,
          calories: 518,
      }),
      headers: [
        { text: 'Dessert', value: 'name' },
        { text: 'Calories', value: 'calories' },
      ]
    }
  },
  mounted() {
    document.addEventListener('wheel', this.onScroll)
  },
  methods: {
    onScroll() {
      console.log('scrolling')
    }
  }
})

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

Inspecting the Nuxt.js application, retrieve the build version using console.log

Currently, my Nuxt site is being hosted on AWS S3 with Cloudfront. Whenever I deploy a new version, I have to invalidate the CloudFront CDN which causes a delay in the deployment process. I want to display the build hash by using console.log(buildHash) wh ...

Exploring the Power of Two jQuery Ajax Functions in Your Script

Is it possible to provide guidance on how I can successfully execute two separate Ajax calls within a single script without encountering conflicts? A sample of the current script structure is as follows: <script type="text/javascript"> $(document).r ...

Looking for a way to toggle the visibility of a dropdown list when clicking on an input in Angular7?

My Angular7 application features a dropdown menu that automatically closes when an item is selected. Additionally, I have implemented functionality to toggle the dropdown open and closed by clicking on an input field. You can view a live example of this be ...

Condensed JQuery condition code for "if" statement

This piece of code is designed to sequentially display 10 questions and control the visibility of each question using the CSS class .hideme. It also sends metrics data to Google Analytics. Although it functions properly, I feel like the code is too leng ...

Experience some issues with the NextJS beta app router where the GET request fails when using fetch, but surprisingly works

Having an issue with a GET request while using NextJS with the APP dir... The function to getProjects from /project route.ts is not triggering properly. console.log("in GET /projects") is never triggered, resulting in an unexpected end of JSON ...

Problem with Jquery Colorbox in firefox

I am using JavaScript to dynamically populate anchor links in a repeater and displaying them in a colorbox iframe. This functionality is working well in IE7, Safari, and Chrome, but encountering an issue in Firefox (version 14.1). In Firefox, the links ar ...

Handling multiple promises with JavaScript/Express Promise.all()

For my latest project, I am developing a movie discussion forum where users can create profiles and list their favorite films. To display the details of these movies, I have integrated the OMDB API with a backend route built using Express. In my initial t ...

Steps for programmatically closing a Dialog Window in a showmodeldialog window

When opening the window, I follow this approach: var MyArgs = new Array(ParmA, ParmB, ParmC, ParmD, ParmE, ParmF); var leftpost = getWindow_TotalWidth() - 1000 - 100; var WinSettings1 = "dialogHeight:580px; dialogWidth:950px;edge:Raised; center:Yes; resi ...

Modifying the hue of Material UI tab label

I attempted to modify the label color of a tab to black, but it seems to be stuck as white. Is this color hard-coded in material-ui? If not, how can I change it? Here's what I've tried: const customStyles = { tab: { padding: '2p ...

How do you switch selection to "hold" mode using Javascript?

In my Markdown preview area, clicking on text will cause the preview area to switch to a markdown source editor automatically, with the cursor jumping to the position corresponding to where it was clicked. function onMouseDown(e) { const range = documen ...

Tips for incorporating MUI into your Redwood JS project

Trying to integrate MUI into Redwood JS has been a challenge for me. I attempted to run the following command in the project directory: yarn add @mui/material Unfortunately, an error message appeared in the console stating: An error Running this command w ...

Discover the exclusive Error 404 dynamic routes available only in the production version of NEXT13! Don

Hey everyone, I'm encountering an issue with NEXT's dynamic routing (Next 13). My folder structure looks like this: - user/ -- [id]/ --- page.js It works fine in dev mode but not in production. What am I trying to do? I've created a "page ...

Leveraging AngularJS for retrieving the total number of elements in a specific sub array

I'm currently working on a to-do list application using Angular. My goal is to show the number of items marked as done from an array object of Lists. Each List contains a collection of to-dos, which are structured like this: [{listName: "ESSENTIALS", ...

Managing the triggering of the automatic transition in view models

My question is straightforward and requires no elaborate explanation. Can Durandal be configured to control the use of transitions when transitioning between viewmodels? The motivation behind wanting to disable the animation is as follows: I have a sear ...

Reacting with Node.js: Capturing a selected option from a dropdown menu and storing it in the database

On my React frontend, I have a select dropdown like this: <select name="level" value={level} onChange={this.handleChange} className="form-control"> <option>Begineer</option> <option>Intermediate</option> <option> ...

Hide the drawer when a user clicks on a currently selected tab

Just starting to explore Material-UI and React here, so please bear with me if I'm making any rookie mistakes. :) I've set up a Drawer component containing a Tabs element with multiple Tab components inside. It's nothing too fancy yet - mos ...

How can I effectively utilize find, match, and filter functions with a reactive array in VueJS?

Having some trouble with understanding .value! :) I'm currently working with VueJS v3 and the Composition API. My goal is to locate the first matching value in a reactive array of people. Typically, this array would be populated through an API call, ...

javascript display error message in innerHTML if passwords do not match

Hello, I found your code to be helpful but I am facing an issue. I want to display a message using innerHTML when the passwords do not match. I have been trying to implement this feature but it is not working for me. Below is my current code. Please provid ...

What is the best way to incorporate a <li> view cap within a div element using JavaScript?

Currently, I am attempting to implement a dynamic <li> view limit within the content of a div. My goal is to display only 3 <li> elements each time the div content is scrolled. Although not confirmed, I believe this example may be helpful: ...

What is the process for configuring sendmail in a node.js environment?

After setting up Sendmail on my Nginx server and configuring SMTP for sending emails in my Node.js project, I still encountered issues with emails not being sent. I tried using Sendmail directly, but I'm unsure of how to properly configure it. Here i ...