Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React,{ Component } from 'react';
  2.  
  3. class Table extends Component{
  4.     click(id){
  5.         if(typeof this.props.onClick === 'function'){
  6.             this.props.onClick(id);
  7.         }
  8.     }
  9.     render(){
  10.         const   length = this.props.headers.length,
  11.                 self = this;
  12.         return(
  13.             <table className='w3-table w3-table-all'>
  14.                 <tbody>
  15.                     <tr>
  16.                         {this.props.headers.map(function(header){
  17.                             return (
  18.                                 <th key={header}>{header}</th>
  19.                             )
  20.                         })}
  21.                     </tr>
  22.                     {this.props.rows.map(function(row, i){
  23.                         return (
  24.                             <tr key={row[row.length-1]} className='w3-hover-gray' onClick={self.click.bind(self, row[row.length-1])}>
  25.                                 {row.map(function(entry, j){
  26.                                     if(j < length){
  27.                                         return (
  28.                                             <td key={j}>{entry}</td>
  29.                                         )
  30.                                     }
  31.                                     return null;
  32.                                 })}
  33.                             </tr>
  34.                         )
  35.                     })}
  36.                 </tbody>
  37.             </table>
  38.         )
  39.     }
  40. }
  41. export default Table;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement