Tips for fixing the table header at the top of the page when scrolling through table rows using ng zorro

My issue lies with implementing ng zorro table and setting position: sticky for the <thead> tag, but it doesn't seem to work.

CSS

.table-fixed thead {
  position: sticky !important;
  top: 0;
  z-index: 999;
  background-color: #000;
  color: #fff;
}

.table-fixed thead th {
  position: sticky !important;
  top: 0;
  z-index: 999;
  background-color: #000;
  color: #fff;
}

HTML

 template: `
    <nz-table #colSpanTable [nzData]="listOfData" nzBordered class='table-fixed'>
      <thead>
        <tr>
          <th>Name</th>
          <th>Age</th>
          <th colspan="2">Home phone</th>
          <th>Address</th>
        </tr>
      </thead>
      <tbody>
        <tr *ngFor="let data of colSpanTable.data; index as i">
          <td>{{ data.name }}</td>
        </tr>
      </tbody>
    </nz-table>

Ensure the table header (thead) remains fixed at the top

Answer №1

Ensure that you specify the y attribute when setting the nzScroll parameter.

<nz-table #customTable [nzData]="dataset" nzBordered [nzScroll]="{ y: '240px' }">

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

Can a component's route be dynamically changed based on its state?

Within an Angular 12 application, there exists a component known as SignUpComponent: export class SignUpComponent implements OnInit { form: FormGroup; result: boolean; constructor(private formBuilder: FormBuilder, private userService: UserService) ...

Locate a div within Flexslider following a callback function

I am currently utilizing Flexslider. Upon completion of each slide, my goal is to locate the content within a div named .extra. Despite attempting to use the after callback function of Flexslider to accomplish this task, I have been unsuccessful in finding ...

What is causing the strings in Netflix's CSS to be invalid?

Upon reviewing the code of various websites such as Netflix and W3Schools, I came across an intriguing observation: upon inspecting certain elements (by using the Inspect Element feature in Firefox Developer Edition), most of the CSS rules/strings appear ...

Utilizing inappropriate HTML attributes

Imagine I have a different layout: <div> <p>My Laptop </p> <p>My Phone </p> </div> With jQuery, if one of these items is clicked, I want to display its value. Would it be acceptable to store extra information in an att ...

The input fields seem to be uncooperative, as I am unable to enter

While working on a code, I suddenly found myself unable to type in the input boxes. Despite trying everything, I still can't identify the cause. Below, you'll find all the code I've written since it could be related to anything. On an unrela ...

Unable to install @angular/fire due to compatibility conflicts

Upon running npm outdated, I attempted to update some outdated packages without fully understanding the implications, thinking it was necessary for updating them. However, what I truly need is to install Angular Fire, as indicated by this error message: ...

How to design the appearance of an HTML form input field

Currently, I am working on a web application using asp.net 2.0 and C#. Within this project, I have an HTML file input control that I would like to customize with some styling, specifically changing the color of the textbox. Despite searching online for sol ...

Develop a dynamic animation using gradient and opacity properties

I'm still getting the hang of HTML, JavaScript, and CSS but I recently made some changes to someone else's code to animate a gradient. The original code used background: rgb, but I switched it to background: rgba. It seems to be working fine, but ...

Issue encountered following npm install and ng new on an Angular project: Error Notification

Since Tuesday, I've been experiencing some difficulties. Currently learning Angular and working on multiple projects daily :D Unfortunately, as of Tuesday, I've been unable to run ng new, npm install, or even ng serve. I've attached screens ...

How crucial is the visibility of Angular services?

As I was progressing through the angular.io tutorial, a particular piece of advice caught my attention here. According to Angular, and I quote, it can only bind to public component properties This statement raised some questions for me. Upon testing wh ...

Implementing a jQuery function to trigger window resize on window load

I'm facing an issue with my resize function where the contents within a window change when it reaches a certain width. I'm trying to achieve this same effect on window load but haven't been successful so far. Here's what I've attem ...

Altering the playback of a flash object using HTML or JavaScript

Can the playback speed of a flash object be adjusted without recompiling the object, like through HTML attributes or JavaScript? Appreciate any help in advance ...

Issues with Bootstrap 5 Carousel Control Button Functionality

My carousel isn't responding when I try to move it by touching the buttons. How can I fix this issue? Code: <div class="container mt-4"> <div id="carouselExampleIndicators" class="carousel slide" data-ri ...

How does using ngFor and ngModel in Angular cause a change in one select to affect others?

I am looking to implement a feature where users can create multiple select dropdowns, choose options for each one, and then aggregate these selections into an array that will be sent to a parent component. My current approach involves using an *ngFor loop ...

Confirm the creation of a data-bound component using unit testing with Angular and Jasmine

Check out this snippet of code... Unit Test: import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { HttpClientTestingModule } from '@angular/common/http/testing'; import { AppComponent } from './search ...

Selecting and Uploading Multiple Files in Internet Explorer (less than version 9)

I have been struggling with selecting and uploading multiple files at once to the server. Here is the code I am currently using: <html> <body> <form action="upload.php" method="post" enctype="multipart/form-data" name="myForm"> <l ...

Encountering login difficulties during initial login attempts may result in automatic logout upon page refresh within Angular+(Node/express).js framework

After attempting to log in for the first time, I noticed that the authentication process in AuthService sets the loggedInStatus to true. However, in AuthGuard, the loggedIn status is set to false, preventing navigation to the dashboard. Additionally, the c ...

The menu dropdown vanishes and the navigation links are no longer visible

I'm currently in the process of designing a custom menu with drop-downs, but I've run into some issues. Strangely enough, everything works perfectly in my fiddle, but when implemented on the actual website, it's not functioning properly. I&a ...

WebStorm disregards tsconfig compiler directives when working with Angular applications

My project structure was created using angular-cli, which includes a root tsconfig.json, src/tsconfig.app.json, and src/tsconfig.spec.json. Despite having the noImplicitAny and strict options enabled in the root configuration, I do not receive error notifi ...

Guide to showcasing object characteristics inside an object in Angular2

My USAFacts object contains properties like StateName, as well as objects like State-Bird which hold information about the state bird. If written in JSON, a record of USAFacts would appear as follows: {"StateName": "PA", "State-Bird": [ { "Name": "Ruffed ...