How can I create a sticky header and footer for an Angular UI Material table, while also ensuring that a common page header remains sticky?

Despite following the documentation for a sticky table header, I encountered an issue where setting the height of .example-container to 100% did not make the table's header stick as intended. table.component.html

<div class="example-container mat-elevation-z8" tabindex="0">
<table mat-table matSort [dataSource]="userdata">
  
     <!--Table Content--!>
    <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
    <tr mat-row *matRowDef="let row; columns: displayedColumns; let i = index"
      [ngClass]="i % 2 === 0 ? 'even-row' : 'odd-row'"></tr>
  </table>
  </div>
    
  <mat-paginator [pageSize]="15" [pageSizeOptions]="[5, 10, 25, 100]" showFirstLastButtons></mat-paginator>

table.component.cs

.example-container {
  height: 100%;
  overflow: auto;
}

table {
  width: 100%;
  margin-top:50px
}
  .mat-paginator-sticky {
    bottom: 0px;
    position: sticky;
    z-index: 10;
  }

header.component.css

.header {
display: flex;
height: 64px;
/* width:446px; */
justify-content: space-between;
background-color: #3f51b5;
position: fixed;
width: 100%;
top: 0;
z-index: 1000;

}

In the header file, .header is a class in the header component.

When attempting to apply a 100% height to the .example-container class, the header failed to remain fixed.

This led to an overlap between the common page header and the table itself.

Answer №1

.custom-container {
  height: calc(100% - 64px); /* Calculating height with header subtracted */
  overflow: auto;
}

table {
  width: 100%;
  margin-top: 64px; /* Adjusting margin for header space */
}

.mat-paginator-sticky {
  bottom: 0;
  position: sticky;
  z-index: 10;
}

.header {
  display: flex;
  height: 64px;
  justify-content: space-between;
  background-color: #3f51b5;
  position: fixed;
  width: 100%;
  top: 0;
  z-index: 1000; /* Keeping header above other elements */
}

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

Angular 11 is throwing an error stating that the type 'Observable<Object>' is lacking certain properties as required by its type definition

My code is producing the following error: TS2739 (TS) Type 'Observable<Object>' is missing the following properties from type 'WeatherForecast': ID, date, temperatureC, temperatureF, summary I'm puzzled as to why this error ...

Is there a way for me to keep an image stationary on the page while allowing overlaying text to move?

Currently, I am exploring the process of coding a website that mimics the style of this particular webpage: . I am particularly interested in learning how to create a scrolling effect for text within a fixed area, while keeping the accompanying images st ...

Unique menu design featuring dynamic floating text and creatively asymmetrical sides

I need help creating a customized menu for my website that resembles the design in this image. https://i.sstatic.net/07Ezu.png The menu layout should consist of three main sections as shown by the dotted boxes: a centered logo, a left side with menu items ...

Dealing with a situation where different functions need to be called based on a condition while using unique button names. This is

<button type="button" class="btn btn-primary ms-4" (click)="update()">Save</button> <button type="button" class="btn btn-primary ms-4" (click)="create()">Add</button> B ...

Counting JQuery Classes in an HTML Document

My task involves creating a dynamic HTML form that allows users to enter card values, which are then counted and styled accordingly. Each set of cards is contained within a <section> element. However, I encountered an issue with my jQuery code where ...

Error: The element 'mdb-icon' is not recognized and cannot be parsed

I am currently utilizing Angular 7 alongside Bootstrap 4, and encountering the following error message in my console. Uncaught Error: Template parse errors: 'mdb-icon' is not a known element: If 'mdb-icon' is an Angular co ...

Floating above a surface to manipulate a title

Wondering if it's possible to achieve this without JavaScript, but that would be the ideal scenario. Here's a snapshot of how my page is structured: ____________________________ | TITLE | |This is a fixed header. I wa ...

Altering the properties of every item within a v-for loop's array

I'm currently exploring Vue's approach to writing JavaScript. Let's consider this situation: In the .vue template <button v-on:click="biggerFont()" class="btn btn-s btn-default" type="button" name="button">A</button> < ...

I am encountering an issue with image sliding when trying to implement it within a ViewBag foreach loop in ASP.NET

I'm currently working on a project that involves displaying images in a slideshow with accompanying text. However, I've encountered an issue where all the images are being displayed in a single line, one after another, instead of looping through ...

In the realm of custom libraries, it is impermissible to declare an accessor within an ambient context

I am working on a project with webpack and TypeScript (Project A) that generates a small library. This library is then utilized in an Angular 8 project (Project B). In Project A, I define a class as follows: export class Foo { private foo: s ...

Align child elements in the middle horizontally within a col-lg-4 class using Bootstrap

I am currently working with Bootstrap 4.3.1 and utilizing flex for my page layout. <div class='row d-flex align-items-center'> <div class='col-lg-12'> <div class="form-group row"> ...

Having trouble loading external CSS in HTML?

I have been attempting to load an external CSS file into my current HTML file without success. I have provided images showcasing the code: View the code here See the output here Currently, I am working on Windows and using Aptana Studio 3 as my IDE. ...

The vertical navigation pills in Bootstrap 4 are not functioning properly as anticipated

I've been referring to the bootstrap 4 documentation for my project. After copying and pasting the code snippet for vertical pills, I noticed it wasn't functioning correctly. Instead of displaying text next to the buttons, it was appearing belo ...

updating an object using its instance in angular: step-by-step guide

Having multiple nested arrays displaying data through HTML recursion in Angular, I am faced with the task of updating specific fields. Directly editing a field is simple and involves assigning its instance to a variable. arr=[{ "name":"f ...

Retrieve data from Outlook Calendar API by utilizing OAuth2 protocol

I have been working with calendar APIs in .NET Core and Angular. After successfully integrating the Google Calendar API, I am now looking to implement the Outlook Calendar API as well. To start off, I need to create a function in Angular that will allow me ...

Maintaining the layout of two columns in Bootstrap 4, responsive design turns them into a single stacked

Currently using Bootstrap v4 with a two-column layout that splits the container in half. On larger screens, the items in each column display correctly. However, on smaller screens, Bootstrap shuffles the items from column 2 into column 1. I am looking to ...

Developing Angular 6 for dynamic HTML navigation tabs

Being new to Angular 6, I recently created tabs in HTML and now need to convert them into Angular 6 while also making them dynamic. Here is the original HTML code: <ul class="nav nav-tabs side_nav" role="tablist"> <li role="presentation" class= ...

loading dynamic content into an appended div in HTML using Angular

Here is the HTML code from my app.component.html file: <button mat-raised-button color="primary" mat-button class="nextButton" (click)="calculatePremium()"> Calculate </button> <div id="calcul ...

Enhance the bubble charts in Kendo UI Graph by adding dimension and depth to the bubbles for a more visually

Is there a way to create a relief effect on the bubbles in Kendo UI Bubble charts? Currently, all bubbles appear flat with the 15 provided themes. You can see an example here: It would be great to have a 3D-style option similar to the pie chart (Uniform s ...

Ways to adjust a column width to be equal to the full width

My HTML table has columns with fixed widths, except for one that I want to expand to fill the remaining space with a minimum width set. I attempted using width: auto, but it didn't achieve the desired result of filling the leftover space. ...