I need to incorporate filtering into typescript, allowing for a dynamic column parameter that can be utilized in various scenarios.
This is my responsibility.
addToList(selectedItems: any, list: any) {
const data = [];
for (const selection of selectedItems) {
data.push(list.value.filter((item: any) => item.idReport === selection));
}
return data;
}
Because of the hardcoded part (v.idRelatorio), the code is limited to a single file.
My goal is to customize it like this:
For example, if I want to filter based on the name column;
addToList(selectedItems: any, list: any, field: any) {
const data = [];
for (const selection of selectedItems) {
data.push(list.value.filter((item: any) => item.field === selection));
}
return data;
}
In the above scenario, the condition would check if the value in the designated column matches the selected item.
If at a later point I specify the age as the field, then the function will search for the age column automatically.