Grouping and calculations
Group records and calculate over the correct result scope.
Grouping helps people scan categories. Footer calculations answer questions about the filtered result: total stock, average price, or number of non-empty values.
Configuration example
Start from the React quick start or Vue quick start. The following file extends their product catalog. Pass this configuration through getTableConfig in React or config in Vue.
import { defineTableConfig } from "@/components/ui/yayaw-table/config/helpers";
import { productConfig } from "./product-config";
export const groupingConfig = defineTableConfig({
...productConfig,
columns: {
...productConfig.columns,
definitions: productConfig.columns.definitions.map((column) =>
column.id === "stock" ? { ...column, defaultCalculation: "sum" } : column
),
},
table: {
...productConfig.table,
enableGrouping: true,
enableCalculations: true,
},
});import { defineTableConfig } from "@/components/ui/yayaw-table-vue/config";
import { productConfig } from "./product-config";
export const groupingConfig = defineTableConfig({
...productConfig,
columns: {
...productConfig.columns,
definitions: productConfig.columns.definitions.map((column) =>
column.id === "stock" ? { ...column, defaultCalculation: "sum" } : column
),
},
table: {
...productConfig.table,
enableGrouping: true,
enableCalculations: true,
},
});Column defaults
defaultCalculation chooses the initial footer calculation. enableCalculation: false excludes a column. enableGrouping: false excludes a column from grouping choices. Persisted views and current user choices can override defaults.
Edit or freeze calculations
The footer is read-only by default: each column shows its calculation (the viewer's choice, else defaultCalculation) as plain text, and columns without one show nothing, so no "Calculate" button sits under columns nobody totals. When no visible column has a calculation, the footer row is not drawn. To change calculations, the viewer turns on Edit calculations in View settings: every calculable column then offers its menu. The switch starts off on each visit and is not saved in views; turning it on also shows a footer an older view saved hidden.
To fix a calculation, set lockCalculation: true on the column: it always shows its defaultCalculation, even while editing, and ignores a choice the viewer made before. A locked column without a defaultCalculation shows nothing. table.lockCalculations: true locks every column; a column's own lockCalculation: false keeps it editable. When every calculable column is locked, the switch is hidden. React and Vue behave the same.
const config = {
...productConfig,
columns: {
...productConfig.columns,
definitions: productConfig.columns.definitions.map((column) =>
column.id === "stock"
? { ...column, defaultCalculation: "sum", lockCalculation: true }
: column
),
},
table: { ...productConfig.table, enableCalculations: true },
};Grouping with server pagination
Groups organize the rows currently loaded on the page. With server pagination, a group may continue on another page; its visible row count is not a global category count. Use server aggregates for totals across the complete filtered result.
When grouping is active, the Group screen in View settings offers a clear action that removes all grouping fields together. React and Vue return to an ungrouped table while preserving the current filters and sorting. This clears grouping only; use Reset view to restore the saved view's complete arrangement.
Calculate the complete filtered result
Provide aggregate when the server can compute the requested calculations efficiently. It receives search, filters, advanced rules and the calculations map. Return results[columnId] with a machine value (raw) and formatted label, plus the matching row count. Without an aggregate action, the table may retrieve additional list pages. Never silently return a current-page subtotal as a full-result total.
Selection and page results
While rows are selected, each footer shows its calculation over the selected rows instead, labelled with their number, such as "Sum · Selection (2)". The result's tooltip gives the other scopes: the page shown when the matching rows span several pages ("This page: 10"), and every matching row under a selection ("All rows: 40"). Both are computed in the browser from the rows it holds, per currency like every local calculation, so the server's aggregate still answers only the complete filtered result. Translation keys: calculations.selection, calculations.page and calculations.all.
Validate a stock total
The stock recipe starts at 18 units. Editing the desk from 12 to 15 should produce 21 units. Filtering to Draft should show zero. Grouping changes presentation; it must not change which records belong to the query.
For mutations, follow the explicit footer-cache refresh in the stock recipe. The verified React registry refreshes row data and footer calculations through separate query keys.
Calculate stock totals
Declare Sum on Stock and enable footer calculations. The stock recipe shows how to refresh totals after a validated write.
Copy this complete configuration beside product-config.ts. Use () => exampleConfig as React’s getTableConfig, or :config="exampleConfig" in Vue.
Sample data. Changes stay in this preview.
import { defineTableConfig } from "@/components/ui/yayaw-table/config/helpers";
import { productConfig } from "./product-config";
export const exampleConfig = defineTableConfig({
...productConfig,
columns: {
...productConfig.columns,
definitions: productConfig.columns.definitions.map((column) =>
column.id === "stock" ? { ...column, defaultCalculation: "sum" } : column
),
},
table: { ...productConfig.table, enableCalculations: true },
});Sample data. Changes stay in this preview.
import { defineTableConfig } from "@/components/ui/yayaw-table-vue/config";
import { productConfig } from "./product-config";
export const exampleConfig = defineTableConfig({
...productConfig,
columns: {
...productConfig.columns,
definitions: productConfig.columns.definitions.map((column) =>
column.id === "stock" ? { ...column, defaultCalculation: "sum" } : column
),
},
table: { ...productConfig.table, enableCalculations: true },
});Limit grouping to a meaningful field
Keep Status groupable and exclude numerical measures from the grouping picker. Table mode supports up to two grouping fields when the schema offers them.
Copy this complete configuration beside product-config.ts. Use () => exampleConfig as React’s getTableConfig, or :config="exampleConfig" in Vue.
Sample data. Changes stay in this preview.
import { defineTableConfig } from "@/components/ui/yayaw-table/config/helpers";
import { productConfig } from "./product-config";
export const exampleConfig = defineTableConfig({
...productConfig,
columns: {
...productConfig.columns,
definitions: productConfig.columns.definitions.map((column) => ({
...column,
enableGrouping: column.id === "status",
})),
},
table: { ...productConfig.table, enableGrouping: true },
});Sample data. Changes stay in this preview.
import { defineTableConfig } from "@/components/ui/yayaw-table-vue/config";
import { productConfig } from "./product-config";
export const exampleConfig = defineTableConfig({
...productConfig,
columns: {
...productConfig.columns,
definitions: productConfig.columns.definitions.map((column) => ({
...column,
enableGrouping: column.id === "status",
})),
},
table: { ...productConfig.table, enableGrouping: true },
});Totals in several currencies
A number column whose numberFormat.currencyColumn names each row's currency is never summed across currencies: sums, averages, medians, minimums, maximums and ranges are computed per currency, and the footer (and React group subtotals) shows one amount per currency, such as "€1,200.00 · $300.00". Counts and shares are unchanged. numberFormat.currencyConversion shows one converted total instead; see amounts in several currencies.