material-table is a relatively new addition to the suite of libraries providing data table functionality in React. The particular claims to fame for material-table is that it is quick to get running and built on Material-UI. In this intro to material-table, I’ll implement a few material-table examples and discuss the pros and cons.
First, some stats:
So we’ve got a table that is relatively popular (read: good community support) and, if you’re already using MUI in your app, material-table doesn’t add too much additional weight. From here, let’s dive into actual code. I will investigate the following:
Here’s the final code sandbox. We’ll build it together in the steps below.
material-table example
If you prefer live coding with commentary, I embedded a video at the end in the Resources section. I also include a gist with the final code there.
I’d peg spinning up the most basic material-table example in CodeSandbox or with create-react-app at less than two minutes. It was as simple as:
import React, { useState } from "react";
import "./styles.css";
import MaterialTable from "material-table";
export default function App() {
const [data, setData] = useState([
{ name: "Jon", job: "Software Dev", age: 29 }
]);
return (
<div className="App">
<h1>Material-Table Demo</h1>
<div style={{ maxWidth: "100%" }}>
<MaterialTable
columns={[
{
title: "Name",
field: "name"
},
{
title: "Occupation",
field: "job"
},
{
title: "Age",
field: "age",
type: "numeric"
}
]}
data={data}
title="Material-Table Demo"
/>
</div>
</div>
);
}
view raw
basic material-table hosted with ❤ by GitHub
The docs were easy to follow and the only dependency is @material-ui/core (m-ui icons are recommended). I’d label this a beginner-friendly library.
#react #programming #reactjs #material-ui #javascript