Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change angular material sort icon

I need to change default arrow icon from angular material matSort to a custom arrow.

The current code

 <mat-table #table [dataSource]="source" matSort (matSortChange)="sortData($event)" [matSortActive]="sort.active" [matSortDirection]="sort.direction">

Is there any way to do this ?

like image 278
Artur Avatar asked Aug 01 '18 13:08

Artur


People also ask

What is matSortDisableClear?

What is matSortDisableClear? matSortDirection: The sort direction of the currently active MatSortable. matSortDisableClear: Whether to disable the user from clearing the sort by finishing the sort direction cycle.

How do I disable mat sort?

We can disable the sorting of a table in 2 ways: We can add property matSortDisabled on matSort directive, or. Add disabled attribute on any single table header.

What is sorting in angular?

15 Nov 2022 / 7 minutes to read. The Grid component has support to sort data bound columns in ascending or descending order. This can be achieved by setting allowSorting property as true. To dynamically sort a particular column, click on its column header.


2 Answers

::ng-deep .mat-sort-header-arrow[style] {

  // Hide default arrow stem
  .mat-sort-header-stem {
    display: none;
  }
  .mat-sort-header-indicator {
    opacity: 1;
    color: black;
    font-weight: bold;

    // Hide default arrow as its composed of left, right and middle
    .mat-sort-header-pointer-left, .mat-sort-header-pointer-right, .mat-sort-header-pointer-middle  {
      display: none;
    }
  }
}

// My custom ascending arrow
[aria-sort="ascending"] {
  ::ng-deep .mat-sort-header-arrow {
    .mat-sort-header-indicator {
      &::before {
        content: "\2191";
        top: -1.6em;
        position: absolute;
      }
    }
  }
}

// My custom descending arrow
[aria-sort="descending"] {
  ::ng-deep .mat-sort-header-arrow {
    .mat-sort-header-indicator {
      &::before {
        content: "\2193";
        top: -2.4em;
        position: absolute;
      }
    }
  }
}
like image 193
amuthan Avatar answered Sep 21 '22 15:09

amuthan


@Artur

You can try this

[aria-sort='ascending'] {
  ::ng-deep .mat-sort-header-arrow{
    .mat-sort-header-indicator {
      &::before{
        font: normal normal normal 1.1rem/1 FontAwesome;
        content: "\f0d7";
        position: absolute;
        top: .2rem;
      }
    }
  }
}

[aria-sort='descending'] {
  ::ng-deep .mat-sort-header-arrow { 
    .mat-sort-header-indicator {
      &::before{
        font: normal normal normal 1.1rem/1 FontAwesome;
        content: "\f0d8";
        position: absolute;
        top: -.9rem;
      }
    }
  }
}
like image 43
Tameshwar Avatar answered Sep 21 '22 15:09

Tameshwar