Код: Выделить всё
applyFilter(): void {
console.log('mockData************', this.mockData);
if (!this.mockData || this.mockData.length === 0) {
console.error('No Data to Filter');
return;
}
let filteredData = this.mockData; // Start with the full data
if (this.identifierFilterValue && this.identifierFilterValue.length > 0) {
filteredData = this.filterByIdentityCheckbox(filteredData);
}
console.log('Filtered Data ', filteredData);
if (this.dataSource) {
this.dataSource.data = filteredData;
this.dataSource.paginator = this.paginator; // Assign paginator here
}
if (this.dataSource && this.dataSource.paginator) {
this.dataSource.paginator.firstPage();
}
}
filterByIdentityCheckbox(data: any[]): any[] {
console.log(
'******Applying filter by identifierFilterValue:',
this.identifierFilterValue
);
if (
!this.identifierFilterValue ||
this.identifierFilterValue.length === 0
) {
console.log('No Identifier Filters are selected return full data');
return [...data];
}
return data.filter((item) => {
console.log('Checking item identifier:', item.identifier);
if (this.identifierFilterValue.indexOf(item.identifier) !== -1) {
console.log('Matched identifier:', item.identifier);
return true;
} else {
console.log('Identifier not matched', item.identifier);
return false;
}
});
}
У меня есть родительский компонент, компонент фильтра и компонент просмотра.>
Подробнее здесь: https://stackoverflow.com/questions/795 ... g-checkbox