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

How do you properly bind multiple events in jQuery and then unbind just a few of them?

Is it possible to bind multiple events, then unbind a couple of them? This is what I'm trying to achieve: When hovering over the element, the background color changes and changes back when hovering out. But when clicking the element, I want to disabl ...

Show the item in the menu with a label that has either subscript or superscript styling

Within the realm of electrons, the application menu is specified: const menuTemplate = [ { label:"Menu Item 1", click(){ //define some behavior } } ]; Is there a method to exhibit the name of the menu item as Me ...

NodeJS error: Attempted to set headers after they have already been sent to the client

As a beginner, I have encountered an error message stating that the API is trying to set the response more than once. I am aware of the asynchronous nature of Node.js but I am struggling to debug this issue. Any assistance would be greatly appreciated. rou ...

What is the best way to add permissions to each role in JavaScript?

I have been attempting to dynamically add data to an HTML table using JavaScript. The data consists of roles and their corresponding permissions, which are retrieved using Laravel's ORM. I have tried utilizing a nested each jQuery function to append t ...

Allow the div to break out of the overflow: hidden property without disrupting the overall page layout

Currently, I am attempting to separate a child element from its parent that has overflow: hidden applied. The main reason for restricting the dimensions of the parent is for a JavaScript workaround. I have experimented with positioning the child element, ...

Switching input types in Android WebView: From Numeric to Password

I am facing an issue with my webview. In the webview, I have three input types: Number Text Password The problem is that when I switch from the number input field to the password input field, the numeric keyboard opens up instead of the qwerty keyboard. ...

Ways to navigate through textarea components within an iframe tag

I am presented with the following HTML structure: <iframe id="screenshare" ref="screenshare" class="fullScreen2"></iframe> To dynamically fill the <iframe> element, I am utilizing JavaScript through the below function: func ...

Leveraging vuejs to dynamically insert a URL within a function

I am attempting to dynamically bind an image path inside a method. It seems feasible, but I'm uncertain if I am implementing the code correctly. Can someone review it? Essentially, I want to retrieve the selected image from the model rather than hardc ...

An issue with MVC Ajax calls to an API resulting in a null model retrieval

I've been scratching my head for hours because I'm facing a strange issue with my API in one project, while everything is working fine in another project! The Problem: Here's the JavaScript code snippet: var data = new FormData(), ...

The Line Break <br/> element does not display properly in Java Servlet code

I recently developed a dynamic web application using servlet. The main component is a form on the index.html page that triggers the servlet's doGet method. Check out an excerpt of my code for the doGet Method below. String firstName = request.getParam ...

What is the best way to tailor my functions to apply only to specific objects within an array, instead of affecting them all?

I am facing an issue where my functions showMore and showLess are triggering for all objects in the array when onClick is fired. I want these functions to be called individually for each object. Both of these functions are responsible for toggling betwee ...

Prevent webpage from resizing when window dimensions change

Whenever I resize my webpage window, the elements start to pile on top of each other and it looks disorganized. For example, when I reduce the window size, YouTube just cuts off everything instead of stacking the images. How can I achieve a similar effec ...

Start the Express server by utilizing Grunt

Can anyone assist me with adding a task to my Gruntfile that will start my Express server instead of the default one? I attempted to create a task and use require("server.js"), but it doesn't seem to be working properly. When I run "grunt mytask", the ...

How do I determine whether an object is a Map Iterator using JavaScript?

I'm working on some NodeJS code that involves a Map Iterator object. How can I accurately determine if a Javascript object is a "Map Iterator"? Here are the methods I have attempted: typeof myMap.keys() returns 'Object' typeof myMap.keys() ...

JavaScript XML Serialization: Transforming Data into Strings

When trying to consume XML in an Express server using express-xml-bodyparser, the resulting object is not very useful. This is the XML: <SubClass code="A07.0"/> <SubClass code="A07.1"/> <SubClass code="A07.2"/> <SubClass code="A07.3" ...

I am currently facing a challenge in animating my ng-show/ng-hide animation

This particular issue has been widely recognized and discussed multiple times in various forums. Despite the extensive search, I have not come across satisfactory solutions. var aniApp = angular.module("aniApp", []); aniApp.controller('mainCtrl&ap ...

Exploring the use of Dividers within Material-UI's Tabs

When attempting to include a Divider or any other element that is not a Tab within Material-UI Tabs, DOM warnings may appear in the console. <Tabs ...> //... <Divider /> //... </Tabs> One workaround for this issue involves creatin ...

React Hamburger Menu not working as intended

I am facing an issue with my responsive hamburger menu. It is not functioning correctly when clicked on. The menu should display the navigation links and switch icons upon clicking, but it does neither. When I remove the line "{open && NavLink ...

Inject a dynamic URL parameter into an iframe without the need for server-side scripting

I'm really stuck and could use some assistance with the following issue, as I am unable to solve it on my own :( When a user is redirected to a form (provided via an iframe), there is a dynamic URL involved: website.com/form?id=123 The code resp ...

JQuery - Select element by clicking outside

I'm trying to figure out how to hide an element when clicking outside of it. Found a solution at: https://css-tricks.com/dangers-stopping-event-propagation/ $(document).on('click', function(event) { if (!$(event.target).closest('#m ...