4

I have a ngx-datatable with Angular 2 that has some very long column names. I would like to duplicate what they do with Auto Height for row (link to documentation) but would settle for just getting the really long names to wrap into multiple lines.

Normally this wouldn't be an issue but with my newness to Angular, I'm stuck. Normal things like overflow-wrap or word-wrap don't seem to work.

My current code:

  <div class="full-width">
    <ngx-datatable
      class='material'
      [rows]='rows'
      [columns]="columns"
      [columnMode]="'standard'"
      [headerHeight]="150"
      [footerHeight]="50"
      [scrollbarH]="true"
      [rowHeight]="'auto'"
      >
    </ngx-datatable>
  </div>
halfer
  • 19,824
  • 17
  • 99
  • 186
av0000
  • 1,917
  • 6
  • 31
  • 51

2 Answers2

21

Adding this to the CSS did the trick. It also centered and vertically aligned the column headers.

.ngx-datatable.fixed-header .datatable-header .datatable-header-inner .datatable-header-cell {
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: normal !important;
  text-align: center !important;
  vertical-align: middle !important;
}
213374you
  • 226
  • 3
  • 3
0

Also, you can try the following code at the ng-template or ngx-datatable-column tag:

[headerClass]="'uk-text-center'" cellClass="uk-text-center"

I used the UI KIT lib, but you can simply create your class at the .scss file, up to you, hope this help who's in doubt.