Django datatable-view custom tabledata

Hi,

using Django-Datatable-views, I’d like to render a column in the table to display an image for each item listed in the table. So column 1 would be image thumbnail, and then column 2 product name, etc.

The URL path to the logo is within my model, but rather than showing the URL I’d like to use this for the source.

<td class="mt-2 d-flex text-center">
    <div class="bg-primary mr-2"><img src="{{ item.product_logo }}"></div>
    <span class=" my-auto">{{ item.product_name }} <b>({{ item.product_symbol|upper }})</b></span>
</td>

But with the data-tables-view template its:

<table class="datatable table text-nowrap text-md-nowrap table-hover mg-b-0">
    <thead>
        <th>{% trans "product_name" %}</th>
        <th>{% trans "product_slug" %}</th>
        <th>{% trans "product_price" %}</th>
    </thead>
    <tbody>
        <td></td>
    </tbody> 
</table>

I cant see this in the documentation on how to customize the table data etc.

Thanks

Tom

It appears to me that you have at least two different options:

  • You could render the html within the view and pass that as the data in your JSON response for that column.
  • You could generate the column data in datatables using a Custom column render function.