What is the best method for preventing horizontal scrolling in a Vuetify DataTable?

Is it possible to prevent the horizontal scrollbar from showing by default in vuetify's data table when there is not enough space on the screen?

https://i.sstatic.net/SyfSc.png

I created a custom wrapper for horizontal scroll with additional features, but I am unable to integrate it with the data table due to its internal logic.

I attempted to disable overflow properties for the .v-data-table and .v-data-table-wrapper classes, however, my attempts were unsuccessful. It seems like I am overlooking something.

Any ideas or suggestions? :(

Answer №1

To disable the scroll feature on the v-data-table__wrapper CSS class, add the following code:

.v-data-table .v-data-table__wrapper{
    overflow-x: hidden;
}

You can toggle the scrolling behavior using this class in the snippet below:

const headers = [{
    text: 'Dessert (100g serving)',
    align: 'start',
    sortable: false,
    value: 'name',
  },
  {
    text: 'Calories',
    value: 'calories'
  },
  {
    text: 'Fat (g)',
    value: 'fat'
  },
  {
    text: 'Carbs (g)',
    value: 'carbs'
  },
  {
    text: 'Protein (g)',
    value: 'protein'
  },
  {
    text: 'Iron (%)',
    value: 'iron'
  },
]

const desserts = [{
    name: 'Frozen Yogurt',
    calories: 159,
    fat: 6.0,
    carbs: 24,
    protein: 4.0,
    iron: 1,
  },
]

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data: {
    headers, desserts, noScroll: false,
  },
})
.no-scroll .v-data-table__wrapper{
    overflow-x: hidden;
}
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/@mdi/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f1979e9f85b1c7df89">[email protected]</a>/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b3c5c6d6c7dad5caf3819dcb">[email protected]</a>/dist/vuetify.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
</head>

<body>
  <div id="app">
    <v-app>
      <v-main>
        <div>
          <v-switch v-model="noScroll" label="disable scroll"/>
        </div>
        <div :class="{'no-scroll': noScroll}" style="width: 300px;">
          <v-data-table
            :headers="headers"
            :items="desserts"
            :items-per-page="5"
            mobile-breakpoint="0"
            class="elevation-1"
          ></v-data-table>
        </div>
        
      </v-main>
    </v-app>
  </div>

  <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fc8a8999bcced284">[email protected]</a>/dist/vue.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cabcbfafbea3acb38af8e4b2">[email protected]</a>/dist/vuetify.js"></script>

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

Mocking module getters in Vue.js test-utils - a step-by-step guide

Within my ContactForm component, I have 2 computed mapGetters: computed: { ...mapGetters(["language"]), ...mapGetters("authentication", ["loading"]), The first one is defined in my store/getters.js: export const language = state => { return stat ...

Unable to modify the color of the alert notification in JavaScript using React

I've been attempting to create an alert component, but I'm facing an issue with adjusting the color of the alert message. Upon enabling dark mode in the navbar (located at the bottom of the navbar component code), an alert message confirming the ...

Creating a visually appealing website with Bootstrap 3

Looking to create a unique HTML design using Bootstrap. So far, this is what I've come up with: Plunker Any suggestions or assistance would be greatly appreciated. ...

Create an eye-catching hexagon shape in CSS/SCSS with rounded corners, a transparent backdrop, and a

I've been working on recreating a design using HTML, CSS/SCSS in Angular. The design can be viewed here: NFT Landing Page Design Here is a snippet of the code I have implemented so far (Typescript, SCSS, HTML): [Code here] [CSS styles here] [H ...

Tips for eliminating excessive spacing between words to achieve justified alignment on a mobile device

please add image description hereMy issue is with using text-align: justify; as it sometimes creates large gaps between words. I attempted to resolve this for mobile devices by using text-justify: inter-word;, but unfortunately, it did not work. @media sc ...

The Vue composition api fails to update the text field's bound value

I've encountered an issue while trying to update an attribute of an object after initialization. Here's a simplified version of my component: <template lang="pug"> div v-text-field(v-model="object.name") v-text-field(v-model="ob ...

Problem with Jquery HTML CSS Slideshow

Currently I am working on integrating two sliders into one webpage using the demo available at . One of the sliders is customized from the Linking demo and I have named them slider1 and slider2 with different styling using global.css for slider-1 and text. ...

Comparison between Bootstrap dropdowns and adjusting document height dynamically

I am in the process of constructing a webpage utilizing Bootstrap 4 Shards. I have several dropdowns, some of which are initially hidden using .d-none. The issue arises when these dropdowns start adding height to the document as they unhide, causing the po ...

"Troubleshooting issue in Django 1.6.2 where CSS styles are not being applied to

I am encountering an issue with this code and would greatly appreciate some assistance. The base.html file contains a {% block content %}{% endblock %}. I have created a Signup.html file structured like this: {%extends 'base.html'%} {% block co ...

When the height of the navigation bar is adjusted, the content on the page is shifted

I am facing a challenge that I need help with. I have a button that, when clicked, should expand the navigation bar to cover the entire screen without pushing down the content below it. However, despite setting the height of the navigation bar to 100vh, th ...

Proper Alignment of Multiple Elements Floating to the Right in a Menu

Although this question has been asked previously, I am facing challenges in getting it to work for my specific scenario. My objective is to showcase a menu bar with a search option and inline text to its left. However, when I attempt to float both elements ...

Webpack is throwing an error due to the Vue component type being labeled as "any"

When using ts 4.2.4 and Vue3, I encountered a strange error while building my vue project: > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c3a2a7aeaaededb3a2a0a083f3edf2edf3">[email protected]</a> build > v ...

Integrating a custom font in Angular.js using a .ttf file

I'm struggling to incorporate a .ttf font file into my Angular.js application. I am unsure of the proper way to import it and make use of it in my css files. Any guidance on utilizing this font file with Angular/CSS would be greatly appreciated! ...

Error message TS2304: Unable to locate the variable 'title' in vite (vue) + typescript environment

My current project uses Vite (Vue) along with Typescript. However, when I execute the command yarn build (vue-tsc --noEmit && vite build), I encounter a series of errors similar to this one: Error TS2304: Cannot find name 'title'. http ...

What do you do when you need to hide a table column that has a colspan

I have been searching for a solution to my unique table structure, but I haven't found any that match my situation. When attempting to hide column A or B, the following code works perfectly: $('table td:nth-child(1),table th:nth-child(1)') ...

"Enhancing Search Functionality using AJAX in Laravel and Vue: Handling Empty Search

My goal is to create a search feature using AJAX and Vue. I have a model named "file" which contains all my files. Next, I created a controller called searchcontroller.php public function search(Request $request) { $files = File::where('name&ap ...

Card carousel rotation

Apologies for the vague title, I'm unsure how to properly label my issue. I have a section set up with cards, but I'm aiming to create something resembling a menu that functions like a carousel. Essentially, I want to include right and left arro ...

Switch between showing and hiding two divs using jQuery

I'm attempting to create a link that will toggle hide/show between two divs, and while this concept is not uncommon, I am facing some difficulties. My HTML structure is as follows: <div id="wrapper"> <div id="tog_A"> <div id="tog ...

Using Zurb Foundation to enable horizontal scrolling on an iPad

This is my first experience building a website with the Zurb Foundation framework, and so far, it's been a pretty smooth process. However, I'm encountering an issue when testing the site on an iPad in portrait orientation - there seems to be som ...

My HTML components are not showing alert messages at the top as expected

My application's alert message is supposed to stay on top of all other HTML elements as the page scrolls. However, it seems to be going behind certain components instead of staying on top like it should. This issue is puzzling because all components u ...