Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change filteredData data logic, implement deep search #19

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions client/src/components/CustomTable/CustomTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,33 @@ const CustomTable = ({
const [modalOpen, setModalOpen] = useState(false);

const filteredData = useMemo(() => {
return tableData.data.filter((item) =>
Object.values(item).some((value) =>
value?.toString()?.toLowerCase()?.includes(searchTerm?.toLowerCase())
)
);
return tableData.data.filter((item) => {
return Object.values(item).some((value) => {
if (Array.isArray(value)) {
// when value is array, iterate over each element and search within each element
return value.some((arrayItem) => {
if (typeof arrayItem === 'object' && arrayItem !== null) {
// If the array element is an object, iterate over its values
return Object.values(arrayItem).some((nestedValue) => {
return nestedValue?.toString().toLowerCase().includes(searchTerm.toLowerCase());
});
} else {
// assume the element is string if the element is not an object
return arrayItem?.toString().toLowerCase().includes(searchTerm.toLowerCase());
}
});
} else if (typeof value === 'object' && value !== null) {
// If value is an object, iterate over its values
return Object.values(value).some((nestedValue) => {
return nestedValue?.toString().toLowerCase().includes(searchTerm.toLowerCase());
});
} else {
// If value is not an object and not an array, assume value is primitive value
return value?.toString().toLowerCase().includes(searchTerm.toLowerCase());
}
});
});

}, [tableData.data, searchTerm]);

const sortedData = useMemo(() => {
Expand Down
Loading