mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 11:55:22 +02:00
fix: resolve DataGrid search and filtering issues by consolidating search logic in filterData and fixing aggregation-aware filtering
This commit is contained in:
+4
-37
@@ -435,43 +435,10 @@ const DataGrid: React.FC<DataGridProps> = ({ data, filters, hasCustomerFilter, a
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0. Global Search Filter
|
// Note: Global Search Filter (searchTerm) is now handled at the flat data level
|
||||||
if (searchTerm) {
|
// in pivotRows using filterData. This ensures that even when grouped by
|
||||||
const rawTerm = searchTerm.trim();
|
// dimensions like 'customer', the search correctly filters the underlying
|
||||||
// Check if it looks like a bulk search (contains newlines or commas)
|
// products before aggregation.
|
||||||
const isBulk = rawTerm.includes('\n') || rawTerm.includes(',') || rawTerm.includes(' ');
|
|
||||||
|
|
||||||
if (isBulk) {
|
|
||||||
const searchTerms = rawTerm
|
|
||||||
.split(/[\s,\n]+/)
|
|
||||||
.map(t => t.trim().toLowerCase())
|
|
||||||
.filter(t => t.length > 0);
|
|
||||||
|
|
||||||
if (searchTerms.length > 0) {
|
|
||||||
result = result.filter(row => {
|
|
||||||
const rowSku = row.sku?.toLowerCase() || '';
|
|
||||||
const rowAsin = row.asin?.toLowerCase() || '';
|
|
||||||
const rowTitle = row.title?.toLowerCase() || '';
|
|
||||||
return searchTerms.some(term =>
|
|
||||||
rowSku.includes(term) ||
|
|
||||||
rowAsin.includes(term) ||
|
|
||||||
rowTitle.includes(term)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const term = rawTerm.toLowerCase();
|
|
||||||
result = result.filter(row => {
|
|
||||||
return (
|
|
||||||
(row.sku?.toLowerCase().includes(term)) ||
|
|
||||||
(row.asin?.toLowerCase().includes(term)) ||
|
|
||||||
(row.title?.toLowerCase().includes(term)) ||
|
|
||||||
(row.line?.toLowerCase().includes(term)) ||
|
|
||||||
(row.customer?.toLowerCase().includes(term))
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1. Filter (Legacy Row Filters)
|
// 1. Filter (Legacy Row Filters)
|
||||||
if (rowFilters.length > 0) {
|
if (rowFilters.length > 0) {
|
||||||
|
|||||||
@@ -1232,8 +1232,16 @@ export const filterData = (
|
|||||||
if (searchTerms.length > 0) {
|
if (searchTerms.length > 0) {
|
||||||
const itemAsin = (item.asin || '').toUpperCase();
|
const itemAsin = (item.asin || '').toUpperCase();
|
||||||
const itemSku = (item.sku || '').toUpperCase();
|
const itemSku = (item.sku || '').toUpperCase();
|
||||||
|
const itemTitle = (item.title || '').toUpperCase();
|
||||||
|
const itemLine = (item.line || '').toUpperCase();
|
||||||
|
const itemCustomer = (item.customer || '').toUpperCase();
|
||||||
|
|
||||||
bulkMatch = searchTerms.some(term =>
|
bulkMatch = searchTerms.some(term =>
|
||||||
itemAsin.includes(term) || itemSku.includes(term)
|
itemAsin.includes(term) ||
|
||||||
|
itemSku.includes(term) ||
|
||||||
|
itemTitle.includes(term) ||
|
||||||
|
itemLine.includes(term) ||
|
||||||
|
itemCustomer.includes(term)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user