Encountering issues with implementing a sticky header feature for Primeng tables

I'm having trouble implementing a sticky header with p-table in my project. I've followed the CSS provided in the documentation for primeng 7 but it's not working as expected. Can someone please assist me with this issue? Thank you!

Below is the template I am using:

<p-table [columns]="cols" #dt [value]="students" [autoLayout]="true" [paginator]="true" [rows]="100" [rowsPerPageOptions]="[100,200,500]" >
    <ng-template pTemplate="header" let-columns>
        <tr>
            <th *ngFor="let col of columns" [pSortableColumn]="col.field">
                {{col.header}}
                <p-sortIcon [field]="col.field"></p-sortIcon>
            </th>
        </tr>
    </ng-template>
    <ng-template pTemplate="body" let-rowData let-columns="columns">
    <tr>
        <td *ngFor="let col of columns">
            {{rowData[col.field]}}
        </td>
    </tr>
</ng-template>

</p-table>

This is the CSS I have applied:

:host ::ng-deep .ui-table .ui-table-thead > tr > th {
            position: -webkit-sticky;
            position: sticky;
            top: 69px;
            box-shadow: 1px 3px 6px 0 rgba(32,33,36,0.10);
        }

        @media screen and (max-width: 64em) {
            :host ::ng-deep .ui-table .ui-table-thead > tr > th {
                top: 99px;
            }
        }

Answer №1

Insert Your CSS into Your Table element rather than a Global Component:

   :host ::ng-deep .ui-table .ui-table-thead > tr > th {
            position: -webkit-sticky;
            position: sticky;
            top: 69px;
            box-shadow: 1px 3px 6px 0 rgba(32,33,36,0.10);
        }

        @media screen and (max-width: 64em) {
            :host ::ng-deep .ui-table .ui-table-thead > tr > th {
                top: 99px;
            }
        }

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

Using jQuery to generate a JSON object dynamically based on the values entered in each input field

I'm facing a situation where I need to extract data from a JSON format using PHP. However, I'm struggling with how to structure the Javascript object in order to dynamically create the JSON format. Here is my current scenario: <input title=" ...

Is it possible to convert a blob to an image file using the FileReader in HTML

client side code <head> <script> var reader = new FileReader(); var objVal; var image = new Image(); reader.onload = function(e) { document.getElementById('propertyImg').setAttribute('src', e.target.result); }; fun ...

Is it possible to tap into the stylus Abstract Syntax Tree (AST) for

Is there a way to access the abstract syntax tree (AST) of the CSS style generated by stylus without re-parsing it using css-parse? I'm curious if the AST of the generated styles can be accessed publicly. ...

The mandatory input field property is malfunctioning, and the color of the input field remains unchanged

<div class="container"> <h1>Register Form</h1> <form> <div class="form-group" > <label for="name">Full Name</label> <input type="text" class="form-control" [ngClass]="{& ...

What is the best way to style an icon in CSS?

I am facing an issue with the following code snippet: <span class="stars">★★☆☆☆ </span> My objective is to style the empty stars differently, but I am unsure how to specifically target them. The following CSS rule does not produc ...

"Encountering issue with React as old state is being sent instead of updated state when invoking

I am encountering an issue with state variables in my react + mobx + MaterialUI frontend. I have a button that should trigger a function to convert certain state variables into an object and send it to another object for further processing. Strangely, when ...

Is CSS causing a overflow when trying to print 210mm by 297mm on A4?

Take a look at this basic HTML code : <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <style type="text/css"> .page { width: 200px; height: 500px; background ...

What are the steps to set up the ionic framework on my Windows 7 system?

I am looking to set up the Ionic framework on my Windows system. However, I encountered an error while trying to install it. The warning 1909 appeared stating that it could not create a shortcut for node.js command prompt.ink. It asked me to verify if th ...

Angular - Automatically update array list once a new object is added

Currently, I'm exploring ways to automatically update the ngFor list when a new object is added to the array. Here's what I have so far: component.html export class HomePage implements OnInit { collections: Collection[]; public show = t ...

When scrolling, the sticky <td> element on the table is overlapping with the sticky <th> header, causing the <td> border to disappear. What is the solution to fix this issue?

I am trying to set up a table that has a fixed header when scrolling up and a fixed first column when scrolling left. I have applied 'position: sticky' with 'top:0' for the header and 'left:0' for the first column. However, I ...

Angular 2 Notification System

My implementation of alert services in the tutorial application seems to be causing some issues. Both the login page and registration page alerts are not working as expected. Any idea what could be wrong? Login Component login(){ this.authenticateLog ...

What is the best way to transfer information between two React.js files?

I am currently finding it inefficient to pass data from App.js to another .js file within React by constantly reading and writing from local storage. I would prefer to only retrieve data from local storage once when the App.js component mounts. App.js: ...

Removing a loaded stylesheet in Angular 4

One of the functions in my codebase is responsible for loading a stylesheet based on the user's language choice, whether it's 'en' or 'ar': addStyleSheet(lang: string) { let headID = document.getElementsByTagName(&apo ...

Introduce a transition effect to the MUI Chip component to enhance user experience when the Delete Icon

When the delete icon appears, it is recommended that the overall width of the chip increases smoothly rather than instantly. Here is the current code structure: CSS: customChip: { "& svg": { position: "relative", display: &quo ...

jQuery does not have the capability to access the href attribute through DOM manipulation

I've been trying to extract the href attribute from a link in my code and create a new link using that attribute. However, I'm facing an issue where the created link doesn't seem to work properly - it keeps showing a 404 error message like t ...

Transforming JQuery Output into an HTML Table Layout

Hello there! I am currently working on parsing an XML file within my web page using jQuery. Here is a snippet of the code: function loadCards(lang) { $.ajax({ type: "GET", url: 'data.xml', dataType: "xml", suc ...

What is the process for changing the name of an element in Angular 2?

I'm feeling a bit lost here ... I need to implement the feature that allows users to edit the name of an element by simply clicking on a button. These elements are all stored in the Storage system. How can I achieve this in my current setup? File: ho ...

Implementing Jquery Table Selection with Custom CSS Class

When I attempted to use the selectable feature on a table with a CSS class applied, the selection did not work. However, when I removed the CSS class, the selection worked perfectly fine. I suspect that the issue lies within the CSS definition, but I' ...

The ng-model does not reflect changes when using the JQuery datepicker

Currently, I have set up two textboxes for users to choose a date. I am utilizing JqQuery's datepicker UI to showcase a small calendar pop-up whenever the user clicks on the textbox. However, an issue arises when I select a date in the calendar popup ...

Dynamic Fill Colors in SVG File Through Vue Components

I am currently developing a unique social media platform using VueJS 3. For the design aspect, I incorporated Twitter's iconic logo saved as an .svg file, easily displayed using the <img /> tag. To modify its color, I utilized the fill="#f ...