如何更改角材排序图标

时间:2018-08-01 13:29:23

标签: angular angular-material frontend angular-material2

我需要将默认箭头图标从角材料matSort更改为自定义箭头。

当前代码

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

有什么办法吗?

6 个答案:

答案 0 :(得分:3)

@Artur

您可以尝试

[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;
      }
    }
  }
}

答案 1 :(得分:2)

类似于@Amuthan的答案,它隐藏了默认显示。此代码必须驻留在全局CSS中。它显示插入符号而不是箭头:

mpi.h

这是结果:Table header with carets for sorting

答案 2 :(得分:0)

Try this.
app.component.ts

import {Component, ViewEncapsulation} from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  encapsulation: ViewEncapsulation.None
})
export class AppComponent {
  title = 'app';
}


app.component.css

    .mat-sort-header-stem {
    height: 3px !important;
    width: 10px !important;
    transform: rotate(180deg) !important;
}
.mat-sort-header-pointer-left, .mat-sort-header-pointer-right {
    width: 7px !important;
    height: 3px !important;
}
.mat-sort-header-pointer-middle{
    width: 0px !important;
    height: 0px !important;
}

答案 3 :(得分:0)

::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;
      }
    }
  }
}

答案 4 :(得分:0)

这就是我做到的方式

seq_a = eval(input("Enter a tuple: "))
seq_b = eval(input("Enter a tuple: "))


for i in seq_a:
    if i in seq_b:
        print("True")
    break
else:
    print("False")

<mat-header-cell *matHeaderCellDef (dblclick)="sortData(column.field)"> {{ column.title }}<mat-icon *ngIf="sort.active==column.field" style="font-size:11pt;color:dimgray;font-weight: 700;padding-left:5px">{{sort.direction=="asc"?"arrow_upward":"arrow_downward"}}</mat-icon></mat-header-cell>

答案 5 :(得分:0)

基于@amuthan解决方案,我想到了这一点,它与下拉菜单使用的箭头相同,并且在悬停时也会显示出来:

.mat-sort-header-arrow[style] {
  .mat-sort-header-stem {
    display: none;
  }
  .mat-sort-header-indicator {
    opacity: 1;
    color: black;
    font-weight: bold;

    .mat-sort-header-pointer-left, .mat-sort-header-pointer-right, .mat-sort-header-pointer-middle  {
      display: none;
    }
  }
}
.mat-sort-header-indicator {
  &::before {
    content: "";
    top: 0.1em;
    position: absolute;
    color: $primary;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid;
    margin: 0 4px;
    transform: rotate(180deg);
    opacity: 0.6;
  }
}


[aria-sort="ascending"] {
  .mat-sort-header-arrow {
    .mat-sort-header-indicator {
      &::before {
        top: 0.1em;
        transform: rotate(180deg);
        opacity: 1;

      }
    }
  }
}

[aria-sort="descending"] {
  .mat-sort-header-arrow {
    .mat-sort-header-indicator {
      &::before {
        top: -0.6em;
        transform: rotate(0);
        opacity: 1;
      }
    }
  }
}