I am currently working on a data table project using data from Firebase. The issue I am facing is related to route navigation with a 'name' parameter. When I click on a link, I want to display only the data that matches the passed 'name' parameter. However, when I click on the link, it shows me all the products from the database in an array of objects. How can I filter this data before passing it to my data-table?
Here is a snippet from my component.ts file:
productCategory: Product[];
filteredProducts: any[];
subscription: Subscription;
tableResource: DataTableResource<Product>;
name;
items: Product[] = [];
itemCount: number;
constructor(
private productService: ProductsService,
private route: ActivatedRoute
) {
this.route.paramMap.subscribe(params => {
let name = params.get("name");
this.name = name;
this.subscription = this.productService.getAll().subscribe(products => {
this.filteredProducts = this.productCategory = products;
// Here, I believe I need to filter the input data before saving it into a variable
let category = products.filter(products => products.category);
console.log(category);
this.InitializeTable(category);
});
});
}
private InitializeTable(products: Product[]) {
this.tableResource = new DataTableResource(products);
this.tableResource.query({ offset: 0 }).then(items => (this.items = items));
this.tableResource.count().then(count => (this.itemCount = count));
}
reloadItems(params) {
if (!this.tableResource) return;
this.tableResource.query(params).then(items => (this.items = items));
}