最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is it possible to add an image to a cell Table in Ant Design Tables? - Stack Overflow

programmeradmin1浏览0评论

I am trying to create a column that in his entries will include a small picture and a name. How can I do so using Ant Design's table?

/ponents/table/ I can't seem to find anything related in the docs or the examples.

I am trying to create a column that in his entries will include a small picture and a name. How can I do so using Ant Design's table?

https://ant.design/ponents/table/ I can't seem to find anything related in the docs or the examples.

Share Improve this question asked Nov 13, 2018 at 23:49 RandomizerRandomizer 5052 gold badges7 silver badges20 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 7

There is a mistake in the accepted answer , here how you do it

{
      title: "Image",
      dataIndex: "ImageURL",  // this is the value that is parsed from the DB / server side
      render: theImageURL => <img alt={theImageURL} src={theImageURL} />  // 'theImageURL' is the variable you must declare in order the render the URL
}

You need to declare theImageURL and then use it with the alt and src.

If you were using the table in a similar way as to the examples shown in their docs.(Using a datasource array)

You could do something like this

const columns = [
 {
    title: '',
    dataIndex: 'image_URL_here',
    render:  () => <img src={`image_URL_here`} />
 }
]

      {
          title: 'Image',
          dataIndex: 'avatar',
          width: 50,
          maxWidth: 50,
          render: (t, r) => <img src={`${r.avatar}`} />
        },
<script src="https://cdnjs.cloudflare./ajax/libs/react/16.6.1/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare./ajax/libs/react-dom/16.6.1/umd/react-dom.production.min.js"></script>

发布评论

评论列表(0)

  1. 暂无评论