Page break in Angular with Chartjs and tables

573 Views Asked by At

I have this html where app-sales-by-category-total is a component using chartjs. This has multiple charts since it's in a for loop.

<div class="sales-cat-total">
  <h2>Sales By Category Total</h2>
  <div class="app-wrapper">
    <ng-container *ngFor="let division of categoryTotalData.divisions">
        <div class="category-tag">
          <div class="cat-item division" [ngStyle]="setBgColor(division.name)">
              <app-sales-by-category-total [month]="categoryTotalData.months" [division]="division"></app-sales-by-category-total>
          </div>
        </div>          
    </ng-container>
  </div>
</div>

Page break won't work. This is my css

.app-wrapper,
.sales-cat-total {
    page-break-after: always; 
    page-break-inside: avoid; 
    -webkit-region-break-inside: avoid;
    break-inside: avoid-page;
}

This is the ouput

enter image description here

Even in tables, page break doesn't seem to work at all with this css:

table {
    page-break-inside: auto;
}

tr {
    page-break-inside: avoid;
}
2

There are 2 best solutions below

0
On

hey you can add br tag

    <ng-container *ngFor="let division of categoryTotalData.divisions">
            <div class="category-tag">
              <div class="cat-item division" [ngStyle]="setBgColor(division.name)">
                  <app-sales-by-category-total [month]="categoryTotalData.months" [division]="division"></app-sales-by-category-total>
              </div>
            </div>   
            </br>       
        </ng-container>
0
On

This is due to ViewEncapsulation. In order to change the view of child you need to use ng-deep pseudo-class

app-sales-by-category-total ::ng-deep {
  table {
    // Style goes here
  }
}