In order to make the filter function like a marketplace filter, I want to only see items related to the selected brand and status.
For example:
partners = [
0:{
year: "2022"
badge_status: "badge-success"
sale_date: "01/07/2022"
item_sold: "OATMEAL STOUT - Mark The Shadow"
month: "JULY"
partner: "BASTARDS"
quantity_items: 1
status: "COMPLETED" // **true**
amount_paid: 1
},
1:{
year: "2022"
badge_status: "badge-danger"
sale_date: "04/07/2022"
item_sold: "IPA - Hector 5 Rounds"
month: "JULY"
partner: "BASTARDS"
quantity_items: 1
status: "Payment error occurred" // **false**
amount_paid: 4
},
2:{
year: "2022"
badge_status: "badge-success"
sale_date: "04/07/2022"
item_sold: "IPA - Hector 5 Rounds"
month: "JULY"
partner: "BASTARDS"
quantity_items: 3
status: "COMPLETED" // **true**
amount_paid: 3
}
]
This is my current array in the database. I need to be able to filter by 'item_sold' and/or 'status'. Each selected item_sold should return an array as shown in the indexed image below
this.filtered2 = function(filtering){
// console.clear()
let filterInput = this.search
let filters = [...this.search].filter(input=> input.value).map(input => ({
filter: input.name,
value: input.value
}))
console.log('Items to search for', filters)
return filtrada.filter(product => {
console.log('PRODUCT', product)
return filters.every(filter =>{
console.log("Filter", filter)
return product[filter.filter] == filter.value
})
})
My initial filter will involve selecting the year, month, and partner:
Therefore, in my new array, I will only display products from the selected partner, sale month, and year
The issue arises when I want to apply another filter, to show only the selected products on my list, and if I set a status (sold/not_sold), it should return filtered products with the chosen status. It should function similar to a marketplace array where selecting a brand or price range affects what is displayed...
Currently, following @nem0z's suggestion, when the first item_sold is selected, it returns the filtered array, but upon selecting the second item_sold, it returns empty [].
THIS.SEARCH will receive a value for each selection made on the HTML page
[Image of table only with item_sold filter][1] [1]: https://i.stack.imgur.com/1E9sn.png