New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mui-react-datatables

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mui-react-datatables

Material-UI Datatables

  • 0.0.14
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Material-UI React Datatablrs

build statusbuild versiondownloads
latestBuild Statusnpm packageNPM Downloads
devBuild Statusnpm packageNPM Downloads

MUI Datatables is a library that takes an array of json data and displays it in a simple, configurable way. This library was inspired by mui-datatables however I plan to address many of the shortcomings of this library in my own implementation such as: a footer row to be used for totals, multi-sorting of columns, key-driven configuration (vs index-based), and more to come.

Getting Started

Installation

npm install mui-react-datatables

or

yarn add mui-react-datatables

Using the table

import MUIDatatable from 'mui-react-datatables'
Table Options
const options = {
	fillEmptyRows: true,
	rowsPerPage: 10,
}
Column Options
const columns = [
    {
        title: "Name",
        Cell: item => `${item.name.first} ${item.name.last}`
    },
    {
        title: "Company",
        accessor: "company",
    },
    {
        title: "Age",
        accessor: "age",
    },
    {
        title: "Phone",
        accessor: "phone",
        sortValue: item => parseInt(item.phone.replace(/[^0-9]+/g,"")),
    },
    {
        title: "Balance",
        accessor: "balance",
        sortValue: item => parseFloat(item.balance.replace(/[^0-9.-]+/g,"")),
    },
    {
        title: "Picture",
        Cell: (item) => <img src={item.picture} style={{width: 32, height: 32}} />,
        visible: false,
    },
]
Optional Refs
const [filters, setFilters] = useState([])
const [sorts, setSorts] = useState([])
Implementation
<MUIDatatable
	title={"My Table"}
	data={data}
	columns={columns}
	options={options}
	filtersRef={setFilters}
	sortsRef={setSorts}
/>

API

<MUIDatatable />

The component accepts the following props:

NameTypeDefaultRequiredDescription
titlestring""falseTitle of the table
optionsobject{}trueOptions to be supplied to table.
columns[object][]trueColumns to be displayed in the table.
data[object][]trueData to be supplied to table.
filtersReffunctionfalseAccessor for filters array.
(filters) => {}
sortsReffunctionfalseAccessor for sorts array.
(sorts) => {}
filteredDataReffunctionfalseAccessor for filtered data.
(filteredData) => {}
options:
NameTypeDefaultRequiredDescription
fillEmptyRowsboolfalsefalseShould the table fill empty rows with blanks.
rowsPerPagenumber10falseNumber of rows displayed on a page.
csvExportbooleantruefalseDisplay CSV export button.
csvFilenamestringtitle || "table"falseFilename for CSV export.
initialSorts[object][]falseInitial sorting list.
initialFilters[object][]falseInitial filtering list.
onRowClickfunctionfalseFunction call when row is clicked.
(row, event) => {}
maxRowHeightnumbernullfalseMax height of a row.
footerRow[object][]falseShould the footer row be displayed.
highlightedRowIdnumbernullfalseid of row to highlight.
loadingbooleanfalsefalseShould table display loading cell.
LoadingCellfunctionfalseComponent to render when loading is true
NoRowsCellfunctionfalseComponent to render when data.length is 0
columns[]:
NameTypeDefaultRequiredDescription
idstringindexfalseUnique identifier. Used for reference in initialSorts and initialFilters
titlestringtrueTitle of the column
accessorstringtrue*Key of value in row to display.
*not required if using Cell
CellfunctionfalseRender function of the cell. Overrides accessor
(value, row) => {}
LoadingCellcomponentfalseLoading component of the cell. Overrides accessor
FooterfunctionfalseRender function of the cell footer.
(data, column) => {}
sortablebooltruefalseCan this column be sorted using column headers.
sortValuefunctionfalseCustom sort value. Defaults to accessor then Cell.
(value, row) => {}
filterablebooltruefalseCan this column be filtered / searched on. Applies to both column filters and global search.
filterValuefunctionfalseCustom filter value. Defaults to accessor then Cell.
(value, row) => {}
filterTypestringselectfalseselect: dropdown based on available values
text: free textfield input
numeric: comparison operations + numeric input
hideablebooltruefalseCan the column be hidden / unhidden
visiblebooltruefalseIs the column visible by default. User can unhide if hideable is set to true
csvHeaderstringtitlefalseHeader for the column.
csvValuestringfalseValue to be exported for cell. Default is what renders to the table.
(value, row) => {}

Keywords

FAQs

Package last updated on 07 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc