1.1.12 • Published 2 years ago

@naum_d/material-ui-table v1.1.12

Weekly downloads
32
License
MIT
Repository
github
Last release
2 years ago

@naum_d/material-ui-table

material-ui-table is a library which help to work with material-ui tables and improve developing experience by adding fully customisable component with multiple props. Note this library required @material-ui/core.

Install

npm install --save @naum_d/material-ui-table
yarn add @naum_d/material-ui-table

Usage

To start work, you should just import MUITable component from @naum_d/material-ui-table

import React from 'react';
import MUITable from '@naum_d/material-ui-table';

const Heroes = () => {
  const table = [
    { name: 'Tony', surname: 'Stark', nickname: 'Iron Man' },
    { name: 'Peter', surname: 'Parker', nickname: 'Spider Man' },
    { name: 'Bruce', surname: 'Banner', nickname: 'Hulk' },
    { name: 'Hank', surname: 'Pym', nickname: 'Ant Man' },
  ];

  const columns = [
    { field: 'name', label: 'Name' },
    { field: 'surname', label: 'Surname' },
    { field: 'nickname', label: 'Hero Nickname' },
  ];

  return <MUITable {...{ table, columns }} />;
};

export default Heroes;

API

Base props

PropType & DefaultDescription
tablearray of objects: []List of values to render in table
columnsarray of objects: []List of columns to render in table
optionsobject: {}Object of options to customise table
methodsobject: {}Object of functions to handle component effects
actionsobject: {}Object of objects to add custom actions

Columns

const columns = [
    { field: 'name', label: 'Name' },
    { field: 'surname', label: 'Surname' },
    { field: 'nickname', label: 'Hero Nickname' },
  ];
PropType & DefaultDescription
fieldstring: REQUIREDKey of object (row) in table array of objects (rows), to set a source of cell value. You can use . for nested objects like parent.child.foo
labelstring: REQUIREDLabel of column
lookupfunction: i => iYou can set function to change display of data. For example, you have date string, then in lookup you can set d => moment(d).format(DD-MM-YYYY)
filterFieldstring: undefinedYou can set field for filter if field differ from target for filtration
canSortboolean: trueEnable column for sorting
canFilterboolean: trueEnable column for filtration
canSearchboolean: trueEnable column for searching
formCellboolena: trueEnable column cells to become input in create or update mode

.customFilter(props)

This is a function which should return custom input component for filtration. Prop types is:

props = {
    name: 'string', // name of filter
    lable: 'string', // label of filter input
    value: 'any', // value of filter
    onChange: 'func',
}

onChange function take two required arguments onChange('filter value', 'filter name')

.customInput(props)

This is a function which should return custom input component for create or update row form. Prop types is:

props = {
    name: 'string', // name of filter
    lable: 'string', // label of filter input
    value: 'any', // value of filter
    onChange: 'func',
}

onChange function take two required arguments onChange('filter value', 'filter name')

Options

PropType & DefaultDescription
sizenumber: 5Rows count per page
pagenumber: 0Setup start page
searchstring: ''Setup search input value
showSearchboolean: trueAdd search input in toolbar
orderstring: 'asc'Setup direction of sort. Available 'asc' & 'desc'
orderBystring: nullSetup column name for sort
canSelectboolean: falseAdd checkboxes for each row and header
selectedarray: []Setup selected rows in format: [{id: rowId}, ...]
showAllboolean: falseAdd button which can show all rows in table
minSizenumber: 5Setup min size for showAll mode when table wrapped
tableSizesarray: [5, 10, 20]Setup sizes for table size selector
showSizeboolean: trueAdd selector of table sizes
withPagingboolean: trueAdd pagination buttons for table
isLoadingboolean: falseActivate a circle progress
showFilterboolean: falseAdd filter row under table header
filtersobject: {}Setup default filters
showRowFormboolean: falseAdd form row under table header
rowFormValuesobject: {}Setup default row form values
treeTableboolean: flaseActivate tree table mode. Display children values of rows
childrenFieldstring: 'children'Setup source of children for tree table mode
parentFieldstring: ''If field exist, make tree table from list of values
serverPagingboolean: falseWhen true, turn off all library methods like (search, filter), and render received table
rowsCountnumber: 0Setup table size

Methods

onRowClick

Handle row click, when canSelect === true, return row and isCheck, else return row

onPageChange

Handle page change, return new page

onPageSizeChange

Handle page size change, return new size

onOrderChange

Handle order change, return order (asc or desc) and column name

onSearchChange

Handle search change, return new search string

onFiltersChange

Handle filters change, return new filters in object {filterName: 'filterVaalue', ...otherFilters}

onSelectAllChange

Handle select all, in canSelect === true, return array of selected

Actions

You can add custom actions in different places in format:

actions = {
    actionName: {
        action1: {
            onClick: () => handleClick,
            component: props => <MyButton {...props} />
        }
        action2: {
            onClick: () => handleClick,
            component: props => <MyButton {...props} />
        }
    }
}

onClick return different values in depends from action.

line

Setup action for each row.

onClick return current row values and method to activate row form for update: onClick: (row, open) => open(true).

cmponent return props and row values: component: (props, row) => <MyComponent {...props} childre={row.id}/>

updateForm

Setup action for update row form.

onClick return object of input fields with values: onClick: formValues => console.log(formValues).

header

Setup action for table header in right top corner.

toolbar

Setup action for table toolbar in right top corner.

onClick return array equal to table and searched and filtered array: onClick: (table, filtered) => console.log(table, filtered).

toolbarSelected

Setup action for table toolbar in right top corner when selected.length > 0.

onClick return array of selected rows: onClick: selectedRows => console.log(selectedRows).

createForm

Setup action for create row form.

onClick return object of input fields with values: onClick: formValues => console.log(formValues).

License

MIT © naum-d

1.1.12

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

4 years ago

1.0.27

4 years ago

1.0.26

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.19

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.11

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.10

4 years ago

1.0.5

4 years ago

1.0.2

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

0.0.5

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.4

4 years ago

0.0.1

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago