Unable to modify text color after implementing mat-sort-header in Angular Datatable

My current setup involves using an Angular data table to display data. I recently added the mat-sort-header functionality, which allowed me to change the font color of the header text. Below is a breakdown of my code:

<section id="main-content">
  <section class="wrapper upload-data-templates">
    <div class="row">
      <div class="form-group has-search" style="padding-top: 38px;margin-left: 15px;">
        <span class="fa fa-search form-control-feedback" style="margin-top: 13px;"></span>
        <input type="text" class="form-control" (keyup)="applyFilter($event.target.value)" placeholder="Search By Report Name" style="height: 46px;width: 180%;">
      </div>
      <div class="col-sm-12" style="padding-top: 30px;">
        <table mat-table matSort [dataSource]="dataSource">

          <!-- Position Column -->
          <ng-container matColumnDef="date">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> Date </th>
            <td mat-cell *matCellDef="let element"> {{element.position}} </td>
          </ng-container>
      
          <!-- Name Column -->
          <ng-container matColumnDef="name">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
            <td mat-cell *matCellDef="let element"> {{element.name}} </td>
          </ng-container>
      
          <!-- Weight Column -->
          <ng-container matColumnDef="download">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> Download </th>
            <td mat-cell *matCellDef="let element"> 
              <a href="https://www.w3schools.com">Log</a> |
              <a href="https://www.w3schools.com">Data report</a> |
              <a href="https://www.w3schools.com">HTML report</a>
            </td>
          </ng-container>
      
          <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
          <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
        </table>
      
        <mat-paginator [pageSizeOptions]="[5, 10, 20]"
                       showFirstLastButtons 
                       aria-label="Select page of periodic elements">
        </mat-paginator>
      </div>
    </div>
  </section>
</section>

The following CSS styles are being applied:

.section {
  width: 100%;
  float: left;
  border-bottom: 1px solid #eee;
}

/* More CSS Code Here */

.mat-header-row {
  background: #005173;
  color: white;
}

The resulting table can be seen in the image below:

https://i.sstatic.net/n0CwB.png

I am currently facing an issue where the header text is not visible, and I have tried adding

.mat-header-row { background: #005173; color: white;}
, but it does not work when mat-sort-header is present. My goal is to make both the header text and sort arrow key appear in white. Any experts able to assist with resolving this problem?

Answer №1

To ensure consistency in styling, apply the following rules to both the header text and arrow:

.mat-header-row {
  background-color: #005173;
}

th.mat-sort-header {
  color: white;
}

:host ::ng-deep .mat-sort-header-arrow {
  color: white;
}

Keep in mind that the arrow will only change to white when the column is sorted.

Check out a demonstration on StackBlitz

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 6: A class with no 'default' modifier must explicitly specify a name

I am encountering this error in my ts.file, as I delve into the world of Angular/Ionic. Can anyone help identify the possible reasons for this? I have attempted multiple solutions to address it, but unfortunately, none have proven successful. import { Co ...

What is the best way to switch on/off data loading from the server with a click

I have a button with a click event that sends a server request each time it is clicked. The request should only be sent when the condition showVersions is true. The functionality of the button historyBtn should act as a toggle. This has been my attempt: ...

Challenges with Ionic 4 - Module '@angular/core/package.json' not found

Having some trouble with an Ionic 4 project code that works perfectly on my Mac but encounters an error when I try to run it on my Windows 10 PC. The specific error message states "Cannot find module '@angular/core/package.json'". Interestingly, ...

Creating a custom autocomplete search using Angular's pipes and input

Trying to implement an autocomplete input feature for any field value, I decided to create a custom pipe for this purpose. One challenge I'm facing is how to connect the component displaying my JSON data with the component housing the autocomplete in ...

Utilizing Skeleton to create a cropped text button on an iPhone

I am currently using Skeleton for my simple CSS needs. While it works fine on desktop, I have noticed that on an iPhone, the text in my button gets cropped as shown in the picture. https://i.stack.imgur.com/EYo2P.png Below is the HTML code I'm using ...

After incorporating lazy loading modules in Angular 8, the main component is rendered twice within the Router outlet

Shown below is the expected User Interface: However, the current UI being displayed is different: This is the content of the app-routing.module.ts file: const routes: Routes=[ {path: '',component: HomeComponent}, {path:'counter', load ...

Error message in Angular 2 Routing: Unable to locate main outlet for loading 'AppComponent'

I am currently working on developing an Angular application and have created a login component. Upon successful login, the user should be directed to the dashboard page. I have built a dashboard component for this purpose. To handle navigation in Angular ...

The value of Angular Input remains unchanged within a FormArray

I am experiencing an issue with the Sequence No in my PreprocessingForm's FormArray. When I add a new row, the Sequence No does not change as expected. <tr class="mat-row" *ngFor="let dynamic of PreprocessingForm.controls.arithmeticI ...

Exploring the functionalities of jQuery and Local Storage: Understanding the Selector's various states

I am currently developing a new feature for font customization on a website. The drop-down menu offers several font options to choose from. When a user clicks on one of these options, the following code is executed: jQuery(function($) { if (localStorage.g ...

Enhancing a Bootstrap 4 navbar menu system with padding tweaks

Just starting out with Bootstrap 4 and creating a practice page with a header to familiarize myself with the navbar system. I have put together this jsFiddle (full code) for reference, but essentially, my page structure is as follows: index.html <nav ...

My router-outlet is malfunctioning when trying to display my component

I am currently diving into learning Angular 2 in order to revamp my personal website. However, I've encountered an issue where my application fails to load the component when I navigate to the appropriate route by clicking on the navigation bar. Insi ...

Struggling to position the newest messages at the bottom of the list

I'm working on creating a web chat system similar to IRC where the latest messages should always be at the bottom of the chat window. Below is my attempt, but unfortunately it's not working as expected: ...

The Material Angular components fail to load

Just started a brand new project using Angular and Material design UPDATE : Check out the live editor on StackBlitz: here Working on implementing the toolbar example, but here's what I have so far: Tried inserting the sample code into the app.compo ...

Separate string by using a regular expression pattern

Looking to parse a dynamic string with varying combinations of Code, Name, and EffectDate. It could be in the format below with all three properties or just pairs like Code-Name, Code-EffectDate, or Name-EffectDate. {"Code":{"value":"1"},"Name":{"value": ...

Firefox won't trigger the `beforeunload` event unless I interact with the webpage by clicking on it

In my quest to handle the beforeunload event in Firefox, I've encountered a small hurdle. It seems to be working smoothly, but only if the user physically interacts with the page by clicking on it or entering text into an input field. Below is the co ...

Exploring the way to reach a specific page in Ionic3

Is there a way to navigate from a child page back to its parent page without the URL getting messed up? It seems like when I try to do this, the child remains unchanged while only the parent page updates. If this is correct, how can I remove the child fr ...

What is the best way to append something to the textContent property of an HTML tag within a markup page?

While working on resolving an XSS vulnerability in the jqxGrid where the cell content is rendered as HTML, I encountered a scenario like this: <a href="javascript:alert('test');">Hello</a>. To address this issue, I am exploring ways t ...

Encountering ng build --prod errors following Angular2 to Angular4 upgrade

Upon completing the upgrade of my Angular2 project to Angular4 by executing the following command: npm install @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @angular/http@latest @an ...

Creating a zebra-striped list using CSS can be done by styling even and odd list items differently

I am facing an issue with Angularjs and the table tag when using group loops. The problem arises in achieving correct zebra striping for the list. How can I solve this to ensure the zebra pattern is applied correctly? <table> <tbody> <tr ...

Items in the Vue.Draggable display can be arranged on both the left and right

Recently delving into Vue.js, I am utilizing Vuedraggable for item dragging in my project. Currently, the items in the draggable div are shown as Text 1 Text 2 Text 3 Text 4 Is there a way to rearrange them to display like this? Text 1 Text 2 Text 3 T ...