Ways to include scrolling specifically for one template

As a newcomer to frontend development, I have recently started learning Vue and the Quasar Framework. I am currently working on a table and trying to set a fixed table name with only the table items scrollable.

<template>
    <q-table
      virtual-scroll
      class="fit"
      :style="'overflow: hidden;'"
    >
      <template v-slot:top >
        <div>Fruits</div>
        <q-space />
        <q-btn icon="search"/>
      </template>

      <template v-slot:fruit="props">
        <div class="q-pa-xs col-xs-12 col-sm-6 col-md-4">
            // my items cards
        </div>
      </template>

      
    </q-table>
 

</template>
<style>
.fit

  .q-table__top,
  .q-table__bottom,
  thead tr:first-child th
    /* bg color is important for th; just specify one */

  thead tr th
    position: sticky
    z-index: 1
  thead tr:first-child th
    top: 0
  /* this is when the loading indicator appears */
  &.q-table--loading thead tr:last-child th
    top: 48px
</style>

Answer №1

When comparing grid mode to row mode in a rendered table, it's evident that the elements are not organized in the same way. In row mode, inspecting the DOM structure reveals a standard table with a header and body.

<div
  class="q-table__container q-table--horizontal-separator column no-wrap q-table__card q-table--no-wrap my-sticky-header-table"
>
  <div class="q-table__top relative-position row items-center">...</div>
  <div
    class="q-table__middle q-virtual-scroll q-virtual-scroll--vertical scroll"
  >
    <table class="q-table">
      <!-- table header -->
      <thead>
        <tr>
          <th class="text-left sortable">...</th>
          <th class="text-center sortable">...</th>
          <th class="text-right sortable">...</th>
          <th class="text-right">Carbs (g)</th>
        </tr>
      </thead>
      <!-- table content -->
      <tbody class="q-virtual-scroll__padding">...</tbody>
      <tbody class="q-virtual-scroll__content" tabindex="-1">...</tbody>
      <tbody class="q-virtual-scroll__padding">...</tbody>
    </table>
  </div>
</div>

To achieve a sticky header row in row mode, apply position: sticky; top: 0; to the <th> elements as follows:

  thead tr th
    position: sticky
    z-index: 1
  thead tr:first-child th
    top: 0

On the other hand, in grid mode, the elements are not structured within a <table>. Instead, they are positioned separately from the header information.

<div
  class="q-table__container q-table--horizontal-separator column no-wrap q-table--grid q-table--no-wrap my-sticky-header-table"
>
  <div class="q-table__top relative-position row items-center">...</div>
  <div class="q-table__middle">
    <table class="q-table">
      <!-- table header -->
      <thead>
        <tr>
          <th class="text-left sortable">...</th>
          <th class="text-center sortable">...</th>
          <th class="text-right sortable">...</th>
          <th class="text-right">Carbs (g)</th>
        </tr>
      </thead>
    </table>
  </div>
  <!-- grid content -->
  <div class="q-table__grid-content row">
    <div class="q-table__grid-item col-xs-12 col-sm-6 col-md-4 col-lg-3">...</div>
    <div class="q-table__grid-item col-xs-12 col-sm-6 col-md-4 col-lg-3">...</div>
    <div class="q-table__grid-item col-xs-12 col-sm-6 col-md-4 col-lg-3">...</div>
    <div class="q-table__grid-item col-xs-12 col-sm-6 col-md-4 col-lg-3">...</div>
    ...
  </div>
</div>

In this case, even though there is a <table>, it only contains the header details, separate from the grid content. Therefore, applying overflow: auto and setting a height to the grid content will keep the header fixed on top while allowing for scrollbar functionality.

.q-table__grid-content
  height: 310px
  overflow: auto

For a visual demonstration, you can check out this working sandbox example.

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

Why isn't my topmenu positioned correctly on screens of varying widths due to responsive CSS?

Welcome, I am in the process of learning CSS and responsive design. I have an index page that consists of a header, top menu, main text content, and footer. The top menu layout works well up to 300px, but when it goes under 300px, only the additional link ...

Guide on dynamically displaying a page based on the response from express/mssql middleware

I have developed a full stack application that includes a registration feature which successfully adds data to the database. Now, I am looking for a way to conditionally display the home page based on whether the login credentials are correct. Within my l ...

Hide the menu when a user taps on an item on mobile or tablet devices

I'm facing a unique challenge and could use some guidance. The issue is with the mobile version of my website, accessible at . On tablets or mobile devices, the menu is condensed into a button. To navigate through the menu, I have to click the button ...

Select a background using the Konvas.js library by clicking on a CSS class

I am attempting to use Konvas.js to change the background when clicking on an image with the imgback class: Link to Code I want to avoid assigning an id to each individual image Here is the code snippet: Jquery: $('.back').click(function(){ ...

"PHP script for submitting a form with a post button

Can anyone help me figure out why the submit function isn't working? I've been trying to solve the problem with no luck so far. Any ideas on what might be causing this issue? <?php if(isset($_POST['submit'])){ echo ("Submit fun ...

Changing the ng-include and ng-controller dynamically in your AngularJS project

I'm working on a section of my webpage that features multiple tabs, each requiring a partial and controller to function properly. My goal is to dynamically switch the ng-include and ng-controller based on the currently selected tab. One challenge I&a ...

conceal the bootstrap navigation bar while the page is being

Struggling to toggle a Bootstrap navbar on scroll? Need some guidance from the pros out there. I admit, my Bootstrap and jQuery skills are pretty basic. The browser console doesn't throw any errors, and I've experimented with fadeIn, fadeOut, add ...

Preventing Redundancy in Angular 2: Tips for Avoiding Duplicate Methods

Is there a way I can streamline my if/else statement to avoid code repetition in my header component? Take a look at the example below: export class HeaderMainComponent { logoAlt = 'We Craft beautiful websites'; // Logo alt and title texts @Vie ...

Attempting to send a Promise to another function for it to return, encountering an error of "Unhandled promise rejection"

My goal is to develop a versatile database update function that can be utilized for creating more customized update functions. Within the module database.js, the following code is present: const {Pool,Client}=require('pg'); const pool=new Pool( ...

Can other JavaScript event listeners be synchronized with an asynchronous event?

My goal is to manipulate a web page using Tampermonkey where there is a button with certain event listeners followed by a redirect. Is it possible for me to insert my own click event handler into the button, which triggers an AJAX request and waits for it ...

What options do I have for personalizing this Google Bar Graph?

I am currently working on creating a Google bar chart. You can view my progress here: http://jsfiddle.net/nGvdB/ Although I have carefully reviewed the Google Bar Chart documentation available here, I am struggling to customize the chart to my needs. Spec ...

limiting the number of HTTP requests within a JavaScript forEach loop

In my current coding situation, I am facing an issue where the HTTP requests are being made simultaneously within a forEach loop. This leads to all the requests firing off at once. const main = async () => { items.forEach(async (i: Item) => ...

What is the process for utilizing SWR to display information from a GraphQL Apollo Server within a NextJS application?

While I can successfully access my GraphQL query using apollo-graphql-studio, and the resolver is configured correctly, I am facing difficulty in rendering the data. Being aware of the performance benefits of swr react-hook in next-js, I intend to fetch d ...

``When multiple elements are clicked, the second click will remove the class

I'm struggling with jQuery. Essentially, I want the first click on "div 1" to add a class to the others and display "lorem ipsum" text, and continue this pattern for the rest. However, if I click on the same div again, the class should be removed and ...

Unleashing the Power of Google Apps Script Filters

Having some data in a Google Sheet, I am looking to filter it based on specific criteria and return corresponding values from another column. Additionally, I need to count the number of elements in the resulting column. Below is an example of the data: Sa ...

What is the most effective method for exchanging variables between programs or threads?

I currently have a program that executes an algorithm processing real-time data. Once per hour, the algorithm's parameters are optimized based on new historical data. Currently, this optimization process is running in a single thread, pausing the rea ...

Modify session variable upon link click

Here is an extension of the question posed on Stack Overflow regarding creating a new page for different PHP ORDER BY statements: Create a new page for different php ORDER BY statement? The task at hand requires changing a session variable and refreshing ...

discovering a new type of mutation through the use of Vuex

Vue Component computed: { score () { this.$store.commit('fetchCoordinates'); console.log(this.$store.getters.cordinate); } } store.js export default { state: { lat:'ok', }, getters:{ cordinate(state){ r ...

Is there a way to gradually reveal JSON data without continuously re-parsing and displaying it on a webpage?

Currently, I am working with a log file that is constantly updated by a running script in real-time. My goal is to effectively monitor the status of this script on a web page using HTML and JavaScript. To achieve this, I have utilized JavaScript to dynamic ...

Upon reloading the page, the Vue getter may sometimes retrieve an undefined value

My blog contains various posts. Clicking on a preview will direct you to the post page. Within the post page, I utilize a getter function to display the correct post (using the find method to return object.name which matches the object in the array). cons ...