Conditional Cell Styling

In order to add conditional cell styles, follow this guide.

Like in excel, it is possible to add conditional cell styling to your table. This is an awesome feature that may help you a lot.

For example, imagine you have a table with the grades on some students. If the grade is bigger than 70, you want to apply a custom style to the cell (e.g. a green background) and if not, another custom style (e.g. red background)

In order to have a table with conditional cell styles, apply this code.

import "./styles.css";
import { CTable } from "react-minimalist-table";

const data = [
  {
    Student: "Cecilia Ovalle",
    Grade: 100
  },
  {
    Student: "Edgar Arroyo",
    Grade: 50
  }
];

export default function App() {
  return (
    <div className="App">
      <CTable
        data={data}
        conditionalCellStyle={[
          {
            columns: ["Grade"],
            validation: (value) => value > 70,
            styleTrue: {
              color: "white",
              background: "#7BCC70"
            },
            styleFalse: {
              color: "white",
              background: "#b43757"
            },
            defaultStyle: {
              color: "black"
            }
          }
        ]}
      />
    </div>
  );
}

Conditional Cell Style Props.

CodeSandbox example https://codesandbox.io/s/crimson-sky-4vxdf?file=/src/App.js

Last updated