1.0.7 • Published 3 years ago

@dsinnovators/multi-level-table v1.0.7

Weekly downloads
-
License
GPL-3.0
Repository
github
Last release
3 years ago

MultiLevelTable

Developed by Ishmum Jawad Khan

NPM JavaScript Style Guide

Description:

A Table is quite easy to build and render. But complexity arises when a nested object is needed to be rendered in a table. Further more complexity arrives when a semantic table is needed to build with pure strategy. Here comes MultiLevelTable developed in Dynamic Solution Innovators. Usage of MultiLevelTable is very easy. Just pass data to the table and define the structure of data and pass it through the structure prop. Add any actions for any object or multi nested object.

Output

MultiLevelTable

Install

npm install --save @dsinnovators/multi-level-table

Usage

Table data

const data = [
  {
    id: 1,
    name: "Lorem University",
    degrees: [
      {
        id: 1,
        name: "B.Sc",
        courses: [
          {
            id: 1,
            name: "Computer Science and Engineering",
          },
          {
            id: 2,
            name: "Electrical and Electronics Engineering",
          },
          {
            id: 3,
            name: "Busniess Administration",
          },
        ],
      },
      {
        id: 2,
        name: "M.Sc",
        courses: [
          {
            id: 1,
            name: "Computer Science and Engineering",
          },
          {
            id: 2,
            name: "Electrical and Electronics Engineering",
          },
        ],
      },
    ],
  },
  {
    id: 2,
    name: "Ipsum University",
    degrees: [
      {
        id: 1,
        name: "B.Sc",
        courses: [
          {
            id: 1,
            name: "Computer Science and Engineering",
          },
          {
            id: 2,
            name: "Busniess Administration",
          },
        ],
      },
      {
        id: 2,
        name: "M.Sc",
        courses: [
          {
            id: 1,
            name: "Computer Science and Engineering",
          },
        ],
      },
    ],
  },
];

Structure

const structure =
  {
    name: "institutions",
    children: [{
      field: "name",
      display: "Institute"
    }],
    array: {
      name: "degrees",
      children: [{
        field: "name",
        display: "Degree"
      }],
      array: {
        name: "courses",
        children: [{
          field: "name",
          display: "Course"
        }],
      },
    },
  };

Action

const actions =
  [
    {
      name: "View Course Details",
      callback: (value) => {
        console.log("Course Details :", value);
      },
    },
    {
      name: "Students",
      callback: (value) => {
        console.log("Students:", value);
      },
    },
  ]

Custom CSS classNames

const className =  {
  table : 'w-full shadow-sm overflow-hidden rounded-lg text-center',
  head : 'text-white bg-gray-700 text-center',
  body : 'p-2 border-solid border border-light-blue-300'
}

Component

import MultiLevelTable from '@dsinnovators/multi-level-table'

const ExamplePage = () => {
  return <MultiLevelTable
    data={data}
    structure={structure}
    actions={actions} //optional
    actionLabel="Manage" //optional
    className={className} //optional
  />
}

Parameters

ParameterRequiredDescriptionDefaultType
datatruefetch data from api or any static dataundefinedArrayOf(object)
structuretruespecify the structure of given dataundefinedobject
actionsfalsetakes array of object {name, callback}. add any actions for nested dataundefinedArrayOf({ name: string, callback: func})
actionLabelfalsegive action label for actionsActionstring
classNamefalsetakes a object {table, head, body}. pass CSS classNames to customize tablesee above{table: string, head: string, body: string}

License

GNU General Public License v3.0

© Dynamic Solution Innovators