Implementing a Vue.js Scrollable Table

I am currently working on a table that is populated using the vue.js v-for method:

<table>
  <tr><th>Name</th><th>Surname</th></tr>
  <tr v-for="user in users"><td>@{{user.name}}</td><td>@{{user.surname}}</td></tr>
</table>

My requirement is to limit the height of this table to a maximum of 300px, and enable scrolling if it exceeds this height.

Setting the max-height and overflow:auto properties in my CSS hasn't been effective due to the way the table is rendered dynamically with vue.

I have attempted adding these parameters directly in CSS and applying them dynamically after loading the table, but without success.

However, I discovered that calling $('table').height() returns the actual height of the rendered table. Perhaps there is a way to leverage this information?

Your assistance in resolving this issue would be greatly appreciated!

Answer №1

Would it be possible for you to encase the table within a <div> element?

This approach allows the div to manage scrolling, while giving the table its own space.

Answer №2

json.package

"default-cssnano-preset": {
      "version": "4.0.7",
      ...
        "postcss-calc": "^7.0.1",

Enclose <b-table or <table> within <template> and then <div>, while adding css

vue.table

<!--wrapper--->
<template>
  <div>
    <b-table
      <!--...--->
    </b-table>
  </div>
</template>



<script>
import { mapGetters, mapMutations } from "vuex";

export default {
  name: "data-table",
  props: ["pageSource"],
  middleware: ["auth", "enable"],
  computed: {
    ...mapGetters(["loggedInUser", "userSettings"]),
  }
  <!--...--->
}
</script



<!-- css at bottom of page -->
<style lang="scss" scoped>

.b-table {
  max-height: calc(100vh - 300px);
  overflow-y: auto;
}
</style>

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

Using shortcode to enhance wordpress post content

I am trying to implement a feature similar to the one found at http://jsfiddle.net/theimaginative/gA63t/ within a wordpress post. I have attempted to create a shortcode for inserting this into a post, but I am encountering difficulties. While I have been s ...

Exploring data elements in a Javascript array

Is there a way to use Javascript or jQuery to address the individual employee number, tasks, and sites in the following JSON array? $.each(mySchedule, function(i, obj) { console.log(obj.employees); }); var mySchedule = { "schedule": { "empl ...

Custom attributes given to Stencil web components in Vite/Vue3 will not trigger any reactions

Short backstory I initially set up my project with a vue-cli environment using Vue 2 and options-api. Recently, I decided to transition to create-vue, which is based on Vite with Vue 3 and Typescript. To incorporate web components from Stencil into my pro ...

The background image is failing to display

I am currently working on a subpage for my website that includes a navigation bar and footer. I am looking to add a background image behind the navigation bar, similar to this design. https://i.stack.imgur.com/j6fDZ.jpg After trying various methods, I at ...

What steps can I take to ensure that my email signature is optimized for mobile devices and responsive

I need assistance with formatting my email signature, which currently includes a simple table with a logo in one column and contact details in the other. I want to modify it to be responsive so that on smaller devices, the logo appears above the contact d ...

Transforming website content into HTML code

I am in need of a solution to convert a webpage into an HTML page programmatically. I have researched several websites, but the information provided only covers converting pages into PDF formats. Currently, my program involves saving a page as .html and th ...

In the modal, update the text and apply the "active" class to a different list item when it is clicked

Let's talk about my menu that includes various categories: <div class="col p-0 m-0"> <ul class="Categories__Menu"> @foreach($categories->take(6) as $category) <li class="active"> <a href ...

leaflet.js - Place a marker when clicked and update its position while dragging

Currently working on a small project that requires the ability to place a marker on an image-map powered by leaflet.js, and update its position if it's dragged. I was using the code below for this functionality but keep getting an error 'marker n ...

Tips for automating the execution of Chrome extension code on pages with infinite scrolling

Creating my debut Chrome extension, I'm developing a tool to substitute text on web pages. The current code effectively operates on content loaded by DOMContentLoaded. However, when pages employ infinite scrolling and new content is added, the text r ...

What happens when Image Buttons are clicked in SAPUI5 and their onchange event is triggered

Is there a way to update the image on a button after it has been clicked? I want it to switch to a different image when activated. var offButton = new sap.ui.commons.Button({ id : "offIcon", icon : "img/off.png" , press :functio ...

Dynamic Data Drive Multi-Series Line Graph

I am currently working on creating a D3 line chart. I have taken the code from the block builder and adjusted it with my own data. While the code is functional, I'm facing an issue where the labels are not showing up when I hover over the line. My ma ...

Generating input fields dynamically in a list and extracting text from them: A step-by-step guide

I am designing a form for users to input multiple locations. While I have found a way to add input boxes dynamically, I suspect it may not be the most efficient method. As I am new to this, I want to ensure I am doing things correctly. Here is how I curren ...

Controlling opacity with jQuery animate() function using a click event

I have a specific requirement for an animation. When the button is clicked, I need the element to transition from 0 opacity to full 1 opacity within 300 milliseconds. The issue I am facing is that when the button is clicked, the animation does not work a ...

js problem with assigning the expression result of a regex operation

Let's talk about a JavaScript string scenario: "h" + "e" + "l" + "l" + "o" This particular string is extracted from a regex query, enclosed within [..], and here's how I'm isolating it: var txt = '"blahblahblah["h"+"e"+"l"+"l"+"o"]fo ...

emulate clicking on a child component element within the parent component's test file

In my testing scenario, I encountered a challenge in simulating the click event of an element that exists in a child component from the parent test file. let card; const displayCardSection = (cardName) => { card = cardName; }; describe('Parent ...

Using an object method within a different object in JavaScript

I am attempting to create two objects, one from each of my classes - a Person object and a Drink object. I then want to invoke the drinking method by passing in a Drink object. However, I am struggling with how to do this. Here is my code, and I can't ...

What is the process for deleting headers in a $http.get call and simultaneously including "application/json" and "text/plain" under the "Accept" header?

I'm relatively new to angularjs and I'm currently working on implementing some new features to an existing Angular JS application. The current API calls are quite intricate so I decided to make a direct call. Below is the code snippet for my new ...

When loading a page with Puppeteer using the setContent method, images may not be loaded

Currently, I am experiencing an issue with Puppeteer where it does not load resources that are specified with relative paths (such as background.png in the image src or in CSS url()). When I try to load the content of a local file using setContent(), the o ...

The column flex-direction property seems to be malfunctioning

Can anyone help me with styling a ul tag using display: flex? I'm trying to order it by column with flex-direction: column;, but for some reason, it's not working. Here is the CSS code for the container: #nav li.four_columns ul.sub-menu { widt ...

alternative for in jQuery version 2

Having some issues with the "on" function in jQuery 2.0.2 when working with dynamically added elements. Below is an example where the second part seems to be failing to work: <button class="btn btn-danger btn-lg" id="hi">Danger</button> ...