What is the process for updating the background color of the header in ngx datatable?

I am looking to change the background color of the table header to blue.

This is the HTML code I have:

<ngx-datatable class="material"  [rows]="rows" [columnMode]="'force'" [headerHeight]="50" [footerHeight]="50"
    [rowHeight]="'auto'" ngClass="{'table-striped': false}">
    <ngx-datatable-column name="ID RECLAMO" prop="idReclamo" class="bg-dark"></ngx-datatable-column>
    <ngx-datatable-column name="SEGNALTO" prop="dataSegnalizione">
        <ng-template let-row="row" ngx-datatable-cell-template>
            {{ row.dataSegnalizione | date:'dd/MM/yyyy' }}
        </ng-template>
    </ngx-datatable-column>
    <ngx-datatable-column name="PRESO IN CARICO IL" prop="dataPresoInCarico">
        <ng-template let-row="row" ngx-datatable-cell-template>
            {{ row.dataChiusura | date:'dd/MM/yyyy' }}
        </ng-template>
    </ngx-datatable-column>
    <ngx-datatable-column name="CHIUSO IL" prop="dataChiusura">
        <ng-template let-row="row" ngx-datatable-cell-template>
            {{ row.dataPresoInCarico | date:'dd/MM/yyyy' }}
        </ng-template>
    </ngx-datatable-column>
    <ngx-datatable-column name="NEGOZIO" prop="codiceNegozio"></ngx-datatable-column>
    <ngx-datatable-column name="MANAGER" prop="manager"></ngx-datatable-column>
    <ngx-datatable-column name="CLIENTE" prop="cliente"></ngx-datatable-column>
    <ngx-datatable-column name="STATO" prop="stato"></ngx-datatable-column>
    <ngx-datatable-column name="GESTIONE" prop="gestione"></ngx-datatable-column>
    <ngx-datatable-column name="CAUSALE RECLAMO" prop="causaleReclamo"></ngx-datatable-column>
    <ngx-datatable-column name="SODDISFAZIONE" prop="soddisfazione"></ngx-datatable-column> </ngx-datatable>

I attempted to do it by using "deep" and "host" but did not achieve the desired outcome.

Answer №1

Check out this CSS code snippet:

  .ngx-datatable ::ng-deep .datatable-header-inner{
    background-color: blue !important;
  }
  .ngx-datatable ::ng-deep .datatable-header-inner .datatable-header-cell-label,
  .ngx-datatable ::ng-deep .datatable-header-inner .sort-btn{
    color: white !important;
  }

View the Stackblitz Demo here

Answer №2

If you are working with css, make sure to include the following styles in your css file.

/deep/ .ngx-datatable .datatable-header {
  background-color: blue;
}

But if you prefer using scss, then you should add these styles in your scss file instead.

::ng-deep {
  .ngx-datatable {
    &.datatable-header {
      background-color: red;
    }
  }
}

To see a live example, check out this StackBlitz.

Thank you and best regards.

Answer №3

To have control over the encapsulation in your component, you can use the ViewEncapsulation.None option. This allows you to manage the styles for the ngx-datatable host without the need for using !important in your CSS.

For example:

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
  encapsulation: ViewEncapsulation.None,
})....

// scss

my-app {
  .ngx-datatable .datatable-header-inner {
    background-color: blue;
  }
}

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

on clicking GTM, obtain a different child element

My HTML code is structured as follows: <div onclick="location.href='https://ford-parts-accessories.myshopify.com/products/ash-cup-coin-holder-with-lighter-element?refSrc=6748959244479&amp;nosto=productpage-nosto-1-fallback-nosto-1';&q ...

Display full desktop version on mobile devices with minimized view and no need for horizontal scrolling

While it may seem unusual, my client has requested temporarily removing responsiveness from the site to view the desktop version on mobile. I initially tried removing the responsive meta tag, but encountered horizontal scrolls on the page. My goal is to di ...

The scrolling speed of my news div is currently slow, and I am looking to increase its

This is the news div with bottom to top scrolling, but it is slow to start scrolling. I want to increase the speed. The current behavior is the div appears from the y-axis of the system, but I want it to start exactly where I define. The scrolling div is ...

How to perfectly align responsive email on iPhone 6

My email design appears aligned to the left on iPhone 6 even though I have used align="center" on the tables and TD's. In my media queries, I have specified a width of 320px with the main table set to width="100%". @media only screen and (max-device- ...

The slider's border-radius is not being maintained as it moves from left to right

We recently implemented a slider on our website, located at . While we added a border-radius to the slider, we noticed that when the images slide, the border-radius is slightly removed... I attempted to contain the parent element with overflow: hidden, bu ...

Error: setPosition function only accepts values of type LatLng or LatLngLiteral. The property 'lat' must be a numerical value in agm-core agm-overlay

Currently, I am utilizing Angular Maps powered by Google @agm-core and agm-overlay to implement custom markers. However, when using the (boundsChange) function on the agm-map component, an error occurs with the message "invalidValueError: setPosition: not ...

Apply a CSS class to the selected radio button when retrieving row data from the table

How can I dynamically add a CSS class to a snippet of code when a radio button is selected? Here's the jQuery Snippet: $(document).ready(function (){ $("input:radio").click(function () { if ($(this).is(":checked")) { var empid ...

Ways to store data in the localStorage directly from a server

I'm facing an issue - how can I store data in localStorage that was received from the server? Should I use localStorage.setItem for this purpose? And how do I handle storing an array in localStorage? Or am I missing something here? import { HttpCli ...

The program encountered an issue: it cannot access the property 'invalid' because it is undefined

I have a scenario where I am utilizing nested FormGroup in Angular, with the parent formGroup in the HTML and skills as the nested form. However, during validation, the controls are not being found. Can anyone provide assistance with thi ...

TypeScript encounters difficulty locating the div element

Recently attempted an Angular demo and encountered an error related to [ts] not being able to locate a div element. import { Component } from "@angular/core"; import { FormControl } from "@angular/forms"; @Component({ selector: "main", template: ' ...

Page cannot be adjusted to fit the viewport

My goal is to have the page fit perfectly within the viewport, but despite using the body properties below, I am still seeing a vertical scrollbar. body { display: grid; grid-template: .8fr 4fr / 1fr 4fr; max-height: 100vh; margin: 0; } I'm w ...

Need help with styling for disabled autocomplete? Check out the attached image

I'm currently working with material-ui and react to create a basic form. Everything is functioning properly except for a small UI issue that I can't seem to figure out how to resolve. When I utilize the browser's auto-complete feature, the i ...

Observable emitting individual characters instead of the entire string in an optional parameter of an activated route

Within an Angular component, I have a method with the following content: this.route.paramMap.pipe( switchMap((params: ParamMap) => { let fooValue = params.get('selectedid'); console.log("inside switch map with value as " + ...

What steps should be followed in order to replicate the border design shown in the

Checkboxes Border Challenge I am looking to connect the borders between my checkboxes. I attempted to use pseudo-borders, but encountered issues with setting the height for responsiveness across various screens. If anyone has suggestions on how to tackl ...

Replace the pixel measurements with percentage values

I have a vision for creating a dynamic full-width slider using a flex-wrapper and multiple child sections. Each section spans the width of the viewport and is aligned in a row. The goal is to move the flex-wrapper by 100% margin-left every time a button ...

What is the best way to enable `child_process.execFile` to utilize an existing running application?

I am currently developing an Electron app that is designed to launch another application, such as Photoshop, using child_process.execFile. However, I have encountered an issue where if Photoshop is already running when child_process.execFile is called, a n ...

Issue with border styling in Material-UI vertical ToggleButtonGroup

In my current front-end project, I have implemented the React Material UI ToggleButtonGroup. For a Multiple Selection example with vertical styling, you can refer to this code snippet: https://codesandbox.io/s/eyk66?file=/demo.js However, I encountered a ...

Increase the size of the NativeScript switch component

Here is the code I am working with: .HTML <Switch style="margin-top: 10" (checkedChange)="onFirstChecked1($event)" row="0" col="1" horizontalAlignment="center" class="m-15 firstSwitchStyle"></Switch> .CSS .firstSwitchStyle{ width: 30%; ...

Leveraging the power of Angular4 to dynamically iterate through SVG elements with the

Currently, I am utilizing SVG for font-icons and it is performing flawlessly. However, I have encountered a significant issue while employing *ngFor in my code: <ion-col col-3 *ngFor="let land of landscape_amenities> <span class="icon-{{land. ...

The `@ViewChild` reference cannot be found

My main challenge is toggling a @ViewChild element using an *ngIf, followed by invoking a native event. This snippet shows my HTML element, tagged with #audioPlayer for extracting it through @ViewChild. <audio #audioPlayer *ngIf="convers ...