Material-UI DataGrid, display sum of column and sum updates according to filter as well

Viewed 2128

I have this Material-UI DataGrid, how can I sum all of the values for the column Total Amount in which this will also be updated once filter is triggerd as well?

I am really unsure on how I can sum the entire column of total amount. Any help would be appreciated. Thank you

Codes:

  const [filterModel, setFilterModel] = React.useState({
    items: [
      {
        columnField: "totalAmount",
        operatorValue: ">",
        value: "200"
      }
    ]
  });

  return (
    <div style={{ height: 400, width: "100%" }}>
      <DataGrid
        // rows={rows}
        columns={columns}
        rows={data}
        components={{
          Toolbar: GridToolbar
        }}
        filterModel={filterModel}
        onFilterModelChange={(newFilterModel) => setFilterModel(newFilterModel)}
      />
    </div>
  );
}
1 Answers

You can create custom footer component, and then pass total value as a prop.

Here I created sandbox with complete solution.

Related