mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 12:25: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
|
||||
if (searchTerm) {
|
||||
const rawTerm = searchTerm.trim();
|
||||
// Check if it looks like a bulk search (contains newlines or commas)
|
||||
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))
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
// Note: Global Search Filter (searchTerm) is now handled at the flat data level
|
||||
// in pivotRows using filterData. This ensures that even when grouped by
|
||||
// dimensions like 'customer', the search correctly filters the underlying
|
||||
// products before aggregation.
|
||||
|
||||
// 1. Filter (Legacy Row Filters)
|
||||
if (rowFilters.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user