How to render specific columns as img ?

How to render specific columns as img ?

ziv@kpmbro.comziv@kpmbro.com Posts: 73Questions: 28Answers: 4
edited November 2016 in General

Hello

I am having some columns in my table that is a url link to an img, so i render them different,
the problem begin when i target more than one column, what actually happening is that the last column targeted set his data to all previous columns.

my code:

            $('#extra_table').DataTable({
              "scrollX": true,
              "scrollY": true,
              "paging": false,
              "bFilter": false,
              "columnDefs": [{
                "targets": [3,4,5,6],
                "data": "description",
                "render": function(data, type, full, meta) {
                  var str = $(data).text();
                  var final_html = '<img src="' + str + '"/>';
                  return final_html;
                }
              }]
            });

What am I doing wrong?
thanks

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,683Questions: 1Answers: 10,498 Site admin
    Answer ✓

    You are setting data": "description", for columns 3, 4, 5 and 6. They will all show the description data.

    Do you actually need that property? Where is the data for the table coming from?

    Allan

  • ziv@kpmbro.comziv@kpmbro.com Posts: 73Questions: 28Answers: 4

    Thanks Allen, that was it.

    :)

This discussion has been closed.