FesaComponents
DataTableRecetas

Export y totales

Exportar todo el resultado filtrado y la fila de totales del servidor.

Exportar todo el resultado filtrado

<SmartDataTable
  export={{
    enabled: true,
    formats: ["csv", "xlsx"],
    filename: "facturas",
    scope: "all",
    fetchAllFn: () => getInvoicesForExportAction({
      q: table.searchTextRef.current,
      ...table.filterValuesRef.current,
    }),
  }}
/>

La action de export repite el where del listado sin skip/take (con un tope sano, p. ej. 10.000 filas). El archivo usa los header de las columnas visibles como cabeceras.

Fila de totales

// En la page action — el servidor suma, no la página cargada:
const [rows, total, sums] = await Promise.all([
  db.invoice.findMany({ where, skip, take, select }),
  db.invoice.count({ where }),
  db.invoice.aggregate({ where, _sum: { amount: true } }),
]);

return {
  data: rows,
  totalRows: total,
  aggregates: { amount: formatCurrency(sums._sum.amount ?? 0) },  // clave = id de columna
};

Nada más: la tabla pinta el tfoot bajo la columna amount, respetando columnas fijas. Fíjala con style.stickyFooter.

En esta pagina