【问题标题】:How to add image in column of React Virtualized library table如何在 React 虚拟化库表的列中添加图像
【发布时间】:2019-01-29 10:36:33
【问题描述】:

如何在 React 虚拟化库表的列中插入图像, 我已经尝试添加列的 dataKey 属性,但它没有加载,有什么解决办法

import React, { Component } from 'react';
import { Column, Table, AutoSizer, Grid } from 'react-virtualized';

class TableComponent extends Component{
	state={
		callLogsColumnsData: null
	}
	componentDidMount(){
		this.setState({callLogsColumnsData: this.props.tableData});
	}
	render(){
		return(
			<Table
				sortBy="rank"
				sortDirection="DESC"
				width={width}
				height={820}
				headerHeight={20}
				rowHeight={60}
				headerClassName='call-logs-table-header'
				rowClassName='call-logs-row-table'
				style={{borderBottom: "solid 1px #000"}}
				onRowClick={this.onRowClick}
				rowCount={this.state.callLogsColumnsData.length}
				rowGetter={({ index }) => this.state.callLogsColumnsData[index]}
			>
				<Column
					label='CALL ID'
					dataKey='callId'
					width={100}
					className="table-column"
				/>
			</Table>
		)
	}
}
export default TableComponent;

【问题讨论】:

    标签: reactjs


    【解决方案1】:

    < Column
    width = {
      130
    }
    label = 'CLI LOCATION'
    dataKey = 'cliLocation'
    cellData = ''
    cellRenderer = {
      this.cliLocationColumnData
    }
    />
    
    cliLocationColumnData = ({
      cellData,
      dataKey
    }) => {
      return ( <
        div >
        <
        img src = {
          GB_FLAG
        }
        alt = 'imageName' / >
        <
        span > {
          dataKey
        } < /span> <
        /div>
      )
    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-05
      • 2021-02-03
      • 2018-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-31
      相关资源
      最近更新 更多