fix: calculo do dao card totalizador

This commit is contained in:
Alessandro Gonçaalves 2025-10-20 17:43:04 -03:00
parent 35aca238ea
commit f342929539
1 changed files with 57 additions and 41 deletions

View File

@ -284,12 +284,28 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
setGlobalFilter("");
};
const totalValor = data.reduce((sum, item) => {
const [totalValor, setTotalValor] = React.useState(0);
React.useEffect(() => {
// Usar dados filtrados da tabela em vez dos dados originais
const filteredData = table.getRowModel().rows.map(row => row.original);
const newTotal = filteredData.reduce((sum, item) => {
const valor =
typeof item.valor === "string" ? parseFloat(item.valor) : item.valor;
return sum + (isNaN(valor) ? 0 : valor);
}, 0);
console.log('🔄 Calculando total:', {
totalRows: table.getRowModel().rows.length,
originalDataLength: data.length,
newTotal,
columnFilters: columnFilters.length,
globalFilter
});
setTotalValor(newTotal);
}, [table, data, columnFilters, globalFilter]);
const exportToExcel = () => {
if (data.length === 0) return;