2.0.5 • Published 4 years ago

react-tabulous v2.0.5

Weekly downloads
46
License
-
Repository
github
Last release
4 years ago

React-Tabulous 🎉

Installation

To use in your own project, install it via npm package.

npm i @syook/react-tabulous

Or you can clone and build it.

git clone git@github.com:syook/react-tabulous.git

npm run build

The files will be under ./lib folder.

Options

a. Available Column Options

OptionDescriptionTypeisRequiredDefault
headerNameName of Column to be shown in headerStringtrue
fieldfield name as in the dataStringtrue
typetype of the fieldStringtrue
cellreturns the value to be shown in the column cellFunctiontrue
isSortableis column sortableBooleanfalse
isSearchableis column searchableBooleanfalse
isFilterableis column filterableBooleanfalse
omitInHideListshould the column be omitted in table and show/hide dropdownBooleanfalse
optionsarray of options if the type is MultiSelect or Single SelectArrayfalse[]

b. Action Config Options : actions will be shown in action column in table

OptionDescriptionType
isVisibleFunction which returns if the action is visible or notFunction
isDisabledFunction which returns if the action is disabled or notFunction
functionFunction to be executed on action eventFunction
iconIcon name to represent the actionFunction
nameName of actionstring
colorcolor of action componentstring
iconColorcolor of iconstring
sizesize of iconstring
invertedto enable inverted behaviour of action elementfunction
iconInvertedto enable inverted behaviour of iconboolean
classNameany custom classname to be applied for action elementstring
iconClassNameany custom classname to be applied for iconstring
hasCustomComponentif the action is any custom component other than buttonboolean
customComponentthe component that needs to returned if the action has custom componentfunction

c. Available Types

TypeFilter queries availableExtra props needed
Stringcontains, does not contains, is, is not, is empty, is not empty
Dateis, is not, is after, is before, is empty, is not empty
Number=, =/ , < , <=, > , >= , is empty, is not empty
SingleSelecthas any of, has none of, is empty, is not emptyoptions: []
MultiSelectis, is not, is empty, is not empty,options: []

Example

...

import ReactTabulous from 'react-tabulous';
import format from 'date-fns/format'
import { Button, Input } from 'semantic-ui-react';

...

onDelete = ids => {
  console.log('onDelete', ids);
};

onShow = rowObject => {
  console.log('onShow', rowObject);
};

onEdit = rowObject => {
  console.log('onEdit', rowObject);
};

onInputChange = ({ rowObject, value: newValue }) => {
  console.log({ rowObject, newValue });
};

columnDefs = [
  {
    headerName: 'Name',
    field: 'name',
    type: 'String',
    cell: rowObject => (
      <Input value={rowObject.name} onChange={(_e, { value }) => this.onInputChange({ value, rowObject })} />
    ),
    isSortable: true,
    isSearchable: true,
    isFilterable: true,
  },
  {
    headerName: 'Description',
    field: 'description',
    type: 'String',
    cell: rowObject => rowObject.description,
    isSortable: true,
    isSearchable: true,
    isFilterable: true,
    isResizable: true,
  },
  {
    headerName: 'Category',
    field: 'category',
    type: 'SingleSelect',
    cell: rowObject => rowObject.category,
    options: ['Grocery', 'Electronics', 'Home', 'Shoes', 'Computers', 'Outdoors', 'Clothing'].map((category, index) => ({
      value: index,
      label: category,
    })),
    isSortable: true,
    isSearchable: true,
    isFilterable: true,
  },
  {
    headerName: 'Price',
    field: 'price',
    type: 'Number',
    cell: rowObject => rowObject.price,
    isSortable: true,
    isSearchable: true,
    isFilterable: true,
    isResizable: true,
  },
  {
    headerName: 'Expertise',
    field: 'isExpertised',
    type: 'Boolean',
    cell: rowObject => (rowObject.isExpertised ? 'Yes' : 'No'),
    isSortable: true,
    isSearchable: false,
    isFilterable: true,
  },
  {
    headerName: 'Availability',
    field: 'availability',
    type: 'MultiSelect',
    cell: rowObject => rowObject.availability.join(', '),
    options: ['Yes', 'No', 'Maybe'].map(a => ({ value: a, label: a })),
    isSortable: true,
    isSearchable: false,
    isFilterable: true,
  },
  {
    headerName: 'Started at',
    field: 'created',
    cell: rowObject => format(new Date(rowObject.created), 'dd-MMM-yyyy hh:mm a'),
    type: 'Date',
    isSortable: true,
    isSearchable: false,
    isFilterable: true,
    isResizable: true,
  },
];

updatingObjectId = () => false;

actionDefs = [
  {
    name: 'Show',
    isVisible: _rowObject => true,
    isDisabled: rowObject => this.updatingObjectId === (rowObject['id'] || rowObject['_id']),
    isLoading: rowObject => this.updatingObjectId === (rowObject['id'] || rowObject['_id']),
    function: this.onShow,
    icon: 'eye',
    color: '#85C1E9',
  },
  {
    name: 'Delete',
    isVisible: rowObject => !rowObject.isDeleted,
    isDisabled: rowObject => this.updatingObjectId === (rowObject['id'] || rowObject['_id']),
    isLoading: rowObject => this.updatingObjectId === (rowObject['id'] || rowObject['_id']),
    function: rowObject => this.onDelete(rowObject),
    icon: 'trash',
    color: '#E8515D',
  },
];

bulkActionDefs = [{ action: 'delete', function: this.onDelete }];

customComponents = () => (
  <>
    <Button disabled size="small" onClick={() => null}>
      Button 1
    </Button>
    <Button onClick={() => null}>Button 2</Button>
  </>
);

...

<ReactTabulous
  actionDefs={this.actionDefs}
  bulkActionDefs={this.bulkActionDefs}
  data={this.state.data || []}
  includeAction={true}
  mandatoryFields={['Name']}
  name={'Table Name'}
  columnDefs={this.columnDefs}>
  {this.customComponents}
</ReactTabulous>

...

Contributing Guidelines

Please refer CONTRIBUTING.md

License

MIT License

2.0.5

4 years ago

2.0.0

4 years ago

0.1.14

5 years ago

0.1.13

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago