1.0.5 • Published 12 months ago

schema-table-component v1.0.5

Weekly downloads
-
License
-
Repository
-
Last release
12 months ago

schema-table-component

This component will render fields dynamically based on openApi schema JSON.

Install

npm install schema-table-component

Usage

Schema Example:

const userSchema ={
  "properties": {
     "id":{
       "type":"string",
       "readOnly": true
     },
    "name": {
      "type": "string", 
      "minLength": 3
    },
    "dob": {
      "type": "string",
      "format": "date"
    },
    "address": {
      "type": "string",
      "maxLength": 250
    }
  },
  "required":["name"]
} 
    import React from 'react';
    import { SchemaTableComponent, IColumnConfig } from "schema-table-component";

    const config:{[keyName: string]: IColumnConfig} ={
        "id":{
            hidden:true
        },
        "dob":{
            title:"Date of Birth"
        }
    }
    
    const Table=()=>{
        const [users, setUsers]= useState();
        
        return <SchemaTableComponent
            data={users || []}
            schema={userSchema}
            width={window.innerWidth}
            height={window.innerHeight - 150}
            config={config}
        />
    }

Component Props

PropTypeDescription
schemaobjectschemaObject to be rendered as a set of fields(example openapi schema).
configobjectcustom UI config {keyName: string: IColumnConfig;}.
dataarraydata props will be rendered from api
onRowClickfunctionit will be navigate to detail of row data
widthnumberthis props will be calculated width of table
heightnumberthis props will be calculated height of table
tableTitlestringcustom title for table your own
isSearchablebooleanif this props is true then the search filed will shown
isSortablebooleanif this props is true then the table to be able to shorting the data

Config

you can import the type of config from the IFieldConfig.

   const config: { [keyName: string]: IColumnConfig } = {}