0.1.0 • Published 1 year ago

react-table-lib v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

React Table

Installation

yarn add react-table-lib

Usage

import Table from 'react-table-lib'
  • Basic Table

    const data = [
      { name: "Earline Stokes", age: 30 },
      { name: "Amina Bergstrom", age: 25 },
      { name: "Kattie Hoppe", age: 20 }
    ]
    
    return (
      <Table data={data}>
    )
  • Column mapped

    const data = [
      { name: "Earline Stokes", age: 30 },
      { name: "Amina Bergstrom", age: 25 },
      { name: "Kattie Hoppe", age: 20 }
    ]
    
    const columns = {
      name: { label: "Full Name", sortable: true },
      age: { label: "Age", format: (data) => data + 'yrs' }
    }
    
    return (
      <Table data={data} columns={columns}>
    )
  • Selectable

    const data = [
      { name: "Earline Stokes", age: 30 },
      { name: "Amina Bergstrom", age: 25 },
      { name: "Kattie Hoppe", age: 20 }
    ]
    
    const columns = {
      name: { label: "Full Name", sortable: true },
      age: { label: "Age", format: (data) => data + 'yrs' }
    }
    
    const handleSelect = (data) => {
      // do something
      // data [{ name: "Earline Stokes", age: 30 }]
    }
    
    return (
      <Table data={data} columns={columns} selectable="multiple" onSelect={handleSelect}>
    )

Table Properties

Props/MethodsDefaultTypeRequiredDetails
data-arraytrueTable Records in array format with each entry holding key : value pair
columns{}objectfalseEach property for data's entry's header property Ref: Columns
selectable-'single' 'multiple'falseSelectable option to select table record based on type single or multiple
onSelect-functionfalseCallback to get selected records details. callback data: record (or) array of records

Columns Properties

PropertytypeDetails
labelstringTable Header column name
sortablebooleanColumn sortable property
formatfunctionFormatting table record for the same column

Demo

Code Sandbox

Note: Please run yarn storybook to see demo. You can run this in your local too to check the same

0.1.0

1 year ago