Maks K
Maks K

Reputation: 3914

ngx-datatable: how to make summary row fixed (on scrolling)?

I made a fixed header

<ngx-datatable
[scrollbarV]="true">

But how to fix summary row too when I am scrolling the page?

enter image description here

 <p-dialog 
  ...
  <ngx-datatable
    ...
    [scrollbarV]="true"
    >

<ngx-datatable-column name="AMOUNT" [summaryTemplate]="totalCost" [flexGrow]="1">
  ...
</ngx-datatable-column>

...

  <ng-template #totalCost>
   ...
  </ng-template>


</p-dialog>

Upvotes: 2

Views: 6761

Answers (1)

iLuvLogix
iLuvLogix

Reputation: 6420

To start off - here's an example with fixed multiline footer including a summary, here's the link to the source

The same can also be applied to the header, so your custom header-component.ts could look like this:

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

@Component({
  selector: 'header-demo',
  template: `
  <ngx-datatable
    class="material"
    [rows]="rows"
    [columns]="columns"
    [columnMode]="'force'"
    [footerHeight]="50"
    [headerHeight]="100"
    [rowHeight]="'auto'"
    [scrollbarV]="true">
    <ngx-datatable-header>
      <ng-template 
        ngx-datatable-header-template 
        let-rowCount="rowCount"
        let-pageSize="pageSize"
        let-selectedCount="selectedCount"
        let-curPage="curPage"
        let-offset="offset">
        <div style="padding: 5px 10px">
          <div>
            <strong>Summary</strong>: Amount
          </div>
          <hr style="width:100%" />
          <div>
            Rows: {{rowCount}} |
            Size: {{pageSize}} |
            Current: {{curPage}} |
            Offset: {{offset}}
          </div>
        </div>
      </ng-template>
    </ngx-datatable-header>
  </ngx-datatable>
`
})
export class HeaderDemoComponent {
  rows = [];

  columns = [
    ...
    ..
    .
  ];

  ...
  ..
  .

}

As you can see it is totally legit to form whatever div-construction in the you would like to achieve..

Hint: Make use of the header and cell class declarations

like in this example to achieve the styling you desire:

 <ngx-datatable-column 
     name="SomeColumn" 
     [headerClass]="'ngxSomeColumnNameHeader'" 
     [cellClass]="'ngxSomeColumnNameCell'"
     prop="SomeColumnName">
     ...
     ..
 </ngx-datatable-column> 

And also consider using [columnMode]="'force'", [rowHeight]="'auto'" & [limit]="12" in the ngx-datatable tag if required..

Upvotes: 2

Related Questions