To convert the provided HTML grid into an Angular Material table, you will need to use the Angular Material table component. First, make sure Angular Material is installed in your project. If you need to install it, run the following command:
ng add @angular/material
Once installed, you can create a table with the Angular Material table components. Below is a basic example of how you can convert your HTML to an Angular Material table. You will need to adapt this example to fit your data structure and requirements:
<!-- Import Angular Material Table Module in your component's module -->
<div class="mb-10">
<h2 class="text-3xl font-medium capitalize">Prêts associés à ce véhicule</h2>
<hr class="my-5"/>
<!-- Angular Material Table -->
<table mat-table [dataSource]="prets" class="mat-elevation-z8">
<!-- Column Definitions -->
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef>Nom</th>
<td mat-cell *matCellDef="let pret">{{pret.pretInfosConducteur?.Nom}} {{pret.pretInfosConducteur?.Prenom}}</td>
</ng-container>
<ng-container matColumnDef="dateStart">
<th mat-header-cell *matHeaderCellDef>Date Début</th>
<td mat-cell *matCellDef="let pret">{{pret.DateDebut}}</td>
</ng-container>
<ng-container matColumnDef="dateEnd">
<th mat-header-cell *matHeaderCellDef>Date Fin</th>
<td mat-cell *matCellDef="let pret">{{pret.DateFin}}</td>
</ng-container>
<ng-container matColumnDef="km">
<th mat-header-cell *matHeaderCellDef>Kms Parcourus</th>
<td mat-cell *matCellDef="let pret">{{pret.KmsParcourus}} Km</td>
</ng-container>
<ng-container matColumnDef="status">
<th mat-header-cell *matHeaderCellDef>Statut</th>
<td mat-cell *matCellDef="let pret">
<span *ngIf="pret.Statut === 'En attente'" class="badge badge-secondary badge-outline">En attente</span>
<span *ngIf="pret.Statut === 'En cours'" class="badge badge-success badge-outline">En cours</span>
<span *ngIf="pret.Statut === 'Annulé'" class="badge badge-danger badge-outline">Annulé</span>
<span *ngIf="pret.Statut === 'Terminé'" class="badge badge-primary badge-outline">Terminé</span>
</td>
</ng-container>
<!-- Header and Row Declarations -->
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
</div>
In your component's TypeScript file, define the columns you want to display:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-vehicle-loans',
templateUrl: './vehicle-loans.component.html',
styleUrls: ['./vehicle-loans.component.css']
})
export class VehicleLoansComponent implements OnInit {
displayedColumns: string[] = ['name', 'dateStart', 'dateEnd', 'km', 'status'];
prets: any[] = []; // Replace with your array of loans
constructor() {}
ngOnInit() {
// Fetch your loans here and assign to this.prets
this.GetInfosConducteurPret();
}
GetInfosConducteurPret() {
// Your existing method to fetch loan data
}
}
Remember to replace pret.pretInfosConducteur?.Nom and similar bindings with the actual properties of your data model.
Ensure you also include MatTableModule in the module imports where your component is declared:
import { MatTableModule } from '@angular/material/table';
@NgModule({
declarations: [
// Your component
],
imports: [
// Other modules
MatTableModule
],
})
export class YourModule { }
Keep in mind that you may need to assign proper classes or components for the badge styles as Angular Material does not provide badge components out of the box. You’ll need to style them according to your preference or use a different component/library suited for badge display.