0.1.2 • Published 4 years ago

react-grid-cattod v0.1.2

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

catodgrid

A react typescript module that returns the plural form of any noun

Installation

npm install@cattod/react-grid --save
yarn add @cattod/react-grid

Usage

React TypeScript

import React , {Component} from "react"
import { CatodGrid ,Catodcolumn,CatodActions} from '@cattod/react-grid';
import "@cattod/react-grid/build/index.css"
interface IRowData {
    make ?:string,
model ?: string,
price ?: number,
date?: string,
rate?: number
}

interface IState {
  columnDefs: Array<Catodcolumn<IRowData>>
  actions: CatodActions<IRowData>[] 
  rowData : Array<IRowData>
}
export class Example extends Component<{}, IState> {
      constructor(props:{}) {
    super(props)
    this.state = {
       columnDefs: [
        {title:"Make",
          icon:"",
          key:"Make",
          displayValue:(rowData)=>{return this.displayValueMake(rowData)}         
          },
          {title:"Model",
          icon:"",
          key:"Model",
          displayValue:(rowData)=>{return this.displayValueModel(rowData)}
          },
          {title:"Price",
          icon:"",
          key:"price"      
          },
          {title:"Rate",
          icon:"",
          key:"rate",
          displayValue: () =>{return StarRate}
      
          }
      ],
       actions: [
        {title:"Delete" , key : "Delete" , icon: "trash-alt", actionFn:(data:IRowData)=>{ this.removeRow(data)}},
        {title:"Edit" , key : "edit" , icon: "edit", actionFn:(data:IRowData)=>{this.addRow(data)}},
        
        ],
         rowData :  [
          { make: "Toyota", model: "Camery", price: 62000, date:"2020/01/01", rate:4},
          { make: "Ford", model: "Mondeo", price: 32000 , date:"2018/01/01", rate:5},
          { make: "Porsche", model: "Boxter", price: 72000, date:"20190/01/01", rate:3 }],
    }

  }

  
 displayValueMake = (data:IRowData):any=>{
  
 
  return `${data.make } ${data.model}`

}
 displayValueModel = (data:IRowData):any=>{

  return data.model

}

 addRow = (data:IRowData)=>{
  console.log(data)

}
 removeRow = (data:IRowData)=>{
  console.log(data)

}

    render(){
         const message= "empty data"
        return(
          <CatodGrid<IRowData>
          message = {message}
         dataRow = {this.state.rowData}
         columnDef={this.state.columnDefs}
        actions = {this.state.actions}
        /> 
        )
    }
}


function StarRate(props) { 

        return(
       <div> 
          {props.value.map((item:number)=>{
        return (  <span key={item}  className={`fas fa-star`}></span>)
    })}

       </div>
        )
  

}