6

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/components/table/ I can't seem to find anything related in the docs or the examples.

Randomizer
  • 475
  • 7
  • 19

3 Answers3

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.

JAN
  • 21,236
  • 66
  • 181
  • 318
5

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`} />
 }
]
Elliot
  • 928
  • 10
  • 17
0

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