2.0.0-alpha.30 • Published 4 years ago

react-material-ui-datatable v2.0.0-alpha.30

Weekly downloads
43
License
MIT
Repository
github
Last release
4 years ago

React MaterialUI Datatable

Build Status npm version Conventional Commits

Fully uncontrolled and client-side datatable based on material design. Designed with React philosophy. Just set your data and receive common manipulations on it: filtering, sorting, pagination and etc.

:book: See Storybook of this component

:warning: ATTENTION! WIP!

This library is under the work. It means, that we can do Breaking Changes during one major alpha version. Please, check the CHANGELOG before update your current version.

Install

npm install react-material-ui-datatable@2.0.0-alpha.30 --save-exact

or

yarn add react-material-ui-datatable@2.0.0-alpha.30 --exact

Demo

Edit 9lz52zlylr

Usage

import { ReactMUIDatatable } from "react-material-ui-datatable";

const columns = [
  {
    name: "firstName",
    label: "First Name"
  },
  {
    name: "lastName",
    label: "Last Name"
  },
  {
    name: "age",
    label: "Age"
  },
  {
    name: "car.make",
    label: "Car make"
  }
];

const data = [
  { firstName: "Kylynn", lastName: "Lathey", age: 19, car: { make: "BWM" } },
  { firstName: "Cly", lastName: "Dukelow", age: 46,  car: { make: "Mitsubishi" } },
  { firstName: "Afton", lastName: "Chaffer", age: 34,  car: { make: "Audi" } },
  { firstName: "Deva", lastName: "Cowope", age: 22 car: { make: "Reno" } }
];

<ReactMUIDatatable title={"Awesome list"} data={data} columns={columns} />;

For more details see Storybook of this component

ReactMUIDatatable's API

Props

NameTypeDefaultDescription
titlestring""Title of your table
columnsObject[][]Options for each column. Detailed description see here
customCellFunctionFunction that returns a string or React component. Used as display for body cell. ({value: string, column: Object, row: Object}) => string \| React.Component
dataObject[][]Your dataset, that you want to display in the table
pagenumber0Current page. Start with 0
perPagenumber5Quantity of displaying items per page.
perPageOptionnumber[]5, 10, 15Per page option. Displayed on the paging panel
selectedDataObject[][]Array of refs of selected data items. For example, [data[0], data[1]] will select first and second row.
selectablebooleantrueEnable selections
filterablebooleantrueEnable filters in toolbar panel
searchablebooleantrueEnable search bar in toolbar panel
toolbarSelectActionsFunctiondefaultToolbarSelectActionsFunction that returns a string or React component. Used as display actions in Toolbar selection. More details you can read here. You can see example in storybook at section Props -> toolbarSelectActions
toolbarActionsFunctionFunction that returns a string or React component. Used to display custom actions in toolbar panel. Signature ({data: Object, computedData: Object, displayData: Object}) => string \| React.Component
rowActionsFunctionFunction that returns a string or React component. Used to display custom actions in each row. Signature ({row: Object, rowIndex: number}) => string \| React.Component
showSearchBarbooleanfalseOpen or close search bar in toolbar panel
searchValuestring""The value by which the search is performed
sortArray{ columnName: '', direction: "ASC" }Set sorting by column name and set direction for sorting. Can be set sort with multiple columns. Direction may be: ASC and DESC
filterValuesObject{}Set filters for columns
onStateChangedFunctionHandler for state changing. Receives event-like object. Signature (event: {name: string, value: string, state: Object}) => any, where name - changed state, value - new value, state - current state of datatable component. Notice, that state contains only changeable values. It useful to restore state after reloading page, for example
localizationObjectdefault localizationMore details you can read here
customNoMatchesFunctionFunction that returns a string or React component. Used as display text if was no matches after applying filters. (localization: string) => string \| React.Component

toolbarSelectActions

(data: Object, selectedData: Object[], updateSelectedData: Function, handleDelete: Function) => string | React.Component
ArgumentTypeDescription
dataObjectCurrent dataset in the table (with applying filters and sort)
selectedDataObject[]Current selected data (their refs)
updateSelectedData( Object[] ) => anyFunction, that apply new selected data
handleDelete( Object[] ) => anyFunction, that delete selected data. For example, you can call it, when you got successful response from your api

localization

Default value
{
  toolbar: {
    searchAction: 'Search',
    filterAction: 'Filters',
    closeSearch: 'Close search',
  },
  filterLists: {
    title: 'Filter',
    allOption: 'All',
    reset: 'Reset',
    noMatchesText: 'No matches',
  },
  toolbarSelect: {
    selectedData: count => `${count} row(s) selected`,
  },
  pagination: {
    rowsPerPage: 'Rows per page',
    displayedRows: ({ from, to, count }) => `${from}-${to} of ${count}`,
  },
  body: {
    noMatchesText: 'No matches',
  },
}
toolbar
NameTypeDefaultDescription
searchActionstring'Search'Label for search button
filterActionstring'Filters'Label for filters button
closeSearchstring'Close search'Label for close button of search bar
filterLists
NameTypeDefaultDescription
titlestring'Filter'Label for title of filter menu
allOptionstring'All'Label for option 'All' of select controls
resetstring'Reset'Label for reset button of filters
noMatchesTextstring'No matches'Text if no matches in autocomplete
toolbarSelect
NameTypeDefaultDescription
selectedDataFunctioncount => `${count} row(s) selected`Function that receives count of selected rows and returns string
pagination
NameTypeDefaultDescription
rowsPerPagestring'Rows per page'Label for select rows per page
displayedRowsFunction({ from, to, count }) => `${from}-${to} of ${count}`Function that receives from, to and count of data elements and returns string

Column option

NameTypeDefaultDescription
namestringName associated to your data"s object
labelstringDisplay column title
sortablebooleantrueEnable / disable sorting by column
filterablebooleantrueEnable / disable filtering by column. false will exclude column from filter panel
searchablebooleantrueIncluding / excluding column from search results

ReactMUIDatatableProvider with ReactMUIDatatableRoot component

If you have separate screens for editing, creating, detailing items or you have your own screens, and you want to save state of your datatable between pages, you can lift state of the table higher with ReactMUIDatatableProvider. It receives all props from description ReactMUIDatatable's API. To draw table just use ReactMUIDatableRoot component. It's already connect to Provider and will receive all props, that was passed into ReactMUIDatatableProvider. See example below.

Example

Soon here will be link to example. Sorry :(

Alternative

  • mui-datatables - multifunctional table based on material ui components

Thanks

2.0.0-alpha.30

4 years ago

2.0.0-alpha.29

5 years ago

2.0.0-alpha.28

5 years ago

2.0.0-alpha.27

5 years ago

2.0.0-alpha.26

5 years ago

2.0.0-alpha.25

5 years ago

2.0.0-alpha.24

5 years ago

2.0.0-alpha.23

5 years ago

2.0.0-alpha.22

5 years ago

2.0.0-alpha.21

5 years ago

2.0.0-alpha.20

5 years ago

2.0.0-alpha.19

5 years ago

2.0.0-alpha.18

5 years ago

2.0.0-alpha.17

5 years ago

2.0.0-alpha.16

5 years ago

2.0.0-alpha.15

5 years ago

2.0.0-alpha.14

5 years ago

2.0.0-alpha.13

5 years ago

2.0.0-alpha.12

5 years ago

2.0.0-alpha.11

5 years ago

2.0.0-alpha.9

5 years ago

2.0.0-alpha.8

5 years ago

2.0.0-alpha.7

5 years ago

2.0.0-alpha.6

5 years ago

2.0.0-alpha.5

5 years ago

2.0.0-alpha.4

5 years ago

2.0.0-alpha.3

5 years ago

2.0.0-alpha.2

5 years ago

2.0.0-alpha.1

5 years ago

2.0.0-alpha.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago