src/app/columns/column-standard.component.ts
import { Component } from '@angular/core';
import { ColumnMode } from 'projects/ngx-datatable/src/public-api';
import { Employee } from '../data.model';
@Component({
selector: 'column-standard-demo',
template: `
<div>
<h3>
Fixed Column Widths
<small>
<a
href="https://github.com/siemens/ngx-datatable/blob/master/src/app/columns/column-standard.component.ts"
target="_blank"
>
Source
</a>
</small>
</h3>
<ngx-datatable
class="material"
[rows]="rows"
[columnMode]="ColumnMode.standard"
[headerHeight]="50"
[footerHeight]="50"
rowHeight="auto"
>
<ngx-datatable-column name="Name" [width]="300">
<ng-template let-value="value" ngx-datatable-cell-template>
{{ value }}
</ng-template>
</ngx-datatable-column>
<ngx-datatable-column name="Gender" [width]="300">
<ng-template let-row="row" let-value="value" ngx-datatable-cell-template>
{{ value }}
</ng-template>
</ngx-datatable-column>
<ngx-datatable-column name="Age" [width]="300">
<ng-template let-value="value" ngx-datatable-cell-template>
{{ value }}
</ng-template>
</ngx-datatable-column>
</ngx-datatable>
</div>
`
})
export class ColumnStandardComponent {
rows: Employee[] = [];
ColumnMode = ColumnMode;
constructor() {
this.fetch(data => {
this.rows = data.splice(0, 5);
});
}
fetch(cb) {
const req = new XMLHttpRequest();
req.open('GET', `assets/data/company.json`);
req.onload = () => {
cb(JSON.parse(req.response));
};
req.send();
}
}