update searchbar on supplier and stock

This commit is contained in:
Enzo
2025-12-11 17:14:23 +01:00
parent 25de3eae4b
commit 8d98a01c22
11 changed files with 62 additions and 21 deletions
@@ -1,4 +1,4 @@
<nz-table [nzData]="suppliers()"
<nz-table [nzData]="filteredSuppliers()"
[nzLoading]="suppliersLoading()"
[nzFrontPagination]="false">
<thead>
@@ -15,7 +15,7 @@
</tr>
</thead>
<tbody style="text-align: center">
@for (supplier of suppliers(); track supplier.id) {
@for (supplier of filteredSuppliers(); track supplier.id) {
<tr>
<td>{{ supplier.name }}</td>
<td>{{ supplier.phone }}</td>
@@ -26,7 +26,7 @@
<td>{{ supplier.deliveryDelay }} jours</td>
<td>
<app-modal-button type="link" [name]="'Voir les produits'" size="45%">
<nz-table [nzData]="suppliers()" [nzFrontPagination]="false">
<nz-table [nzData]="filteredSuppliers()" [nzFrontPagination]="false">
<thead>
<tr class="text-center">
<th>Produit</th>
@@ -1,4 +1,4 @@
import {Component, inject, OnInit, signal, viewChild} from '@angular/core';
import {Component, computed, inject, OnInit, signal, viewChild} from '@angular/core';
import {ModalNav} from "../modal-nav/modal-nav";
import {NzDividerComponent} from "ng-zorro-antd/divider";
import {NzIconDirective} from "ng-zorro-antd/icon";
@@ -42,6 +42,23 @@ export class SupplierTable implements OnInit {
await this.fetchSuppliers();
}
private searchQuery = signal<string>('');
filteredSuppliers = computed(() => {
const q = this.searchQuery().toLowerCase().trim();
if (!q) return this.suppliers();
return this.suppliers().filter(s => {
const name = (s.name ?? '').toLowerCase();
return name.includes(q);
});
});
applySearch(query: string) {
this.searchQuery.set(query);
}
async fetchSuppliers() {
this.suppliersLoading.set(true);
try {