0.0.14 • Published 4 years ago

mui-react-datatables v0.0.14

Weekly downloads
34
License
ISC
Repository
github
Last release
4 years ago

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.
columnsobject[]trueColumns to be displayed in the table.
dataobject[]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.
initialSortsobject[]falseInitial sorting list.
initialFiltersobject[]falseInitial filtering list.
onRowClickfunctionfalseFunction call when row is clicked. (row, event) => {}
maxRowHeightnumbernullfalseMax height of a row.
footerRowobject[]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 valuestext: free textfield inputnumeric: 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) => {}
0.0.14

4 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10-0

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.8-0

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.6-2

5 years ago

0.0.6-3

5 years ago

0.0.6-4

5 years ago

0.0.6-1

5 years ago

0.0.6-0

5 years ago

0.0.5

5 years ago

0.0.5-3

5 years ago

0.0.5-2

5 years ago

0.0.5-1

5 years ago

0.0.4-1

5 years ago

0.0.5-0

5 years ago

0.0.4

5 years ago

0.0.4-0

5 years ago

0.0.3

5 years ago

0.0.2-2

5 years ago

0.0.2

5 years ago

0.0.2-1

5 years ago

0.0.2-0

5 years ago

0.0.1

5 years ago