GithubHelp home page GithubHelp logo

hudali95 / react-tabulous Goto Github PK

View Code? Open in Web Editor NEW

This project forked from syook/react-tabulous

0.0 0.0 0.0 5.14 MB

A configurable UI Table for React

License: MIT License

CSS 7.92% JavaScript 90.55% HTML 1.53%

react-tabulous's Introduction

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 [email protected]:syook/react-tabulous.git

npm run build

The files will be under ./lib folder.

Options

a. Available Column Options

Option Description Type isRequired Default
headerName Name of Column to be shown in header String true
type type of the field String true
field String='path to get value to be displayed' function='function should return string' String or function true
cell returns the element to be shown in the column cell Function false
isSortable is column sortable Boolean false
isSearchable is column searchable Boolean false
isFilterable is column filterable Boolean false
omitInHideList should the column be omitted in table and show/hide dropdown Boolean false
options array of options if the type is MultiSelect or Single Select Array false []
isResizable is column resizable Boolean false false
fixed String='left' or 'right', where to fix the column String false null
defaultWidth to fix column width to a value in pixels if width exceeding this threshold Number false null

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

Option Description Type
isVisible Function which returns if the action is visible or not Function
isDisabled Function which returns if the action is disabled or not Function
function Function to be executed on action event Function
icon Icon name to represent the action Function
name Name of action string
color color of action component string
iconColor color of icon string
size size of icon string
inverted to enable inverted behaviour of action element function
iconInverted to enable inverted behaviour of icon boolean
className any custom classname to be applied for action element string
iconClassName any custom classname to be applied for icon string
hasCustomComponent if the action is any custom component other than button boolean
customComponent custom component above the table along with filter button (has access to filtered data in table layout, visible columns, searchText and filtered original data ), {tableData, columns, searchText, filteredTableData} function

c. Available Types

Type Filter queries available Extra props needed
String contains, does not contains, is, is not, is empty, is not empty
DateTime/Date is, is not, is after, is before, is empty, is not empty
Number =, =/ , < , <=, > , >= , is empty, is not empty
SingleSelect has any of, has none of, is empty, is not empty options: []
MultiSelect is, is not, is empty, is not empty, options: []

d. Component Props

Prop Description Default Required Type
mandatoryFields '' true
data data for the table true
columnDefs is, is not, is empty, is not empty, true
actionDefs contains, does not contains, is, is not, is empty, is not empty false
bulkActionDefs is, is not, is after, is before, is empty, is not empty false
name name of the table false string
includeAction to show actions column false false boolean
isShowSerialNumber to show serial number column false false boolean
enableIcon to show icon in serial number column false false boolean
showIcon function which returns JSX element(Icon) to render false function
isAllowDeepSearch allow a deep search in the data for the searched keyword false false boolean
emptyCellPlaceHolder placeholder for empty cells false string
accentColor colors for top bar buttons false string
hideBulkCount hide bulk select count for bulk actions false false boolean
showResetButton display reset button true false boolean

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,
    fixed: 'left',
    defaultWidth: 100,
  },
  {
    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,
    defaultWidth: 200,
  },
];

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}
  isShowSerialNumber={true}
  isAllowDeepSearch={true}
  showResetButton={true}>
  {this.customComponents}
</ReactTabulous>

...

Contributing Guidelines

Please refer CONTRIBUTING.md

License

MIT License

react-tabulous's People

Contributors

mayanksyook avatar pallavihegde1 avatar pallavi-syook avatar ameysyook avatar nithil-syook avatar anees-syook avatar harsh-syook avatar anik3tra0 avatar nithil avatar deepak-syook avatar abhishek-syook avatar mayankkhajanchi avatar dependabot[bot] avatar somashekar-syook avatar henriquelbsouza avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.