Skip to main content

Summary Row

material-table-core supports a summary row.

FieldType
renderSummaryRowfuncThe function to create the summary row

The function will be called with following parameters for each column:​

parameterType
columnsColum[]All columns of the table
columnColumnThe column to render the cell of
indexnumberThe index of the current column
dataRowData[]All data of the table
currentDataRowData[]The data currently displayed on the page

The function can return a value and optional styles for cell that should display a value in the summary row:​

FieldType
valueReact.ReactNodeThe value to print in the given cell of the summary row
styleReact.CSSPropertiesOptional css properties to style the cells

Examples​

Live Editor
function SummaryTable() {
  const data = [
    { name: "Engel", surname: "Dominik", age: 27 },
    { name: "Seb", surname: "Teko", age: 24 },
  ];
  const columns = [
    {
      title: "Name",
      field: "name",
    },
    {
      title: "Surname",
      field: "surname",
    },
    {
      title: "Age",
      field: "age",
      type: "numeric",
    },
  ];
  return (
    <MaterialTable
      data={data}
      columns={columns}
      renderSummaryRow={({ column, data }) =>
        column.field === "age"
          ? {
              value: data.reduce((agg, row) => agg + row.age, 0),
              style: { background: "red" },
            }
          : undefined
      }
    />
  );
}
Result
Loading...