fix: calculo do dao card totalizador
This commit is contained in:
parent
35aca238ea
commit
f342929539
|
|
@ -284,12 +284,28 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
|
||||||
setGlobalFilter("");
|
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 =
|
const valor =
|
||||||
typeof item.valor === "string" ? parseFloat(item.valor) : item.valor;
|
typeof item.valor === "string" ? parseFloat(item.valor) : item.valor;
|
||||||
return sum + (isNaN(valor) ? 0 : valor);
|
return sum + (isNaN(valor) ? 0 : valor);
|
||||||
}, 0);
|
}, 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 = () => {
|
const exportToExcel = () => {
|
||||||
if (data.length === 0) return;
|
if (data.length === 0) return;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue