1
I am mounting a table with the JS framework Datatables
I process the data via Server-side through the JSON
in the first column I would like to display a photo,the name of this photo comes via JSON.
How to do?
Example of how I’m testing:
<table id="example" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
<thead>
<tr>
<th></th>
<th>Foto</th>
<th>ID Historico</th>
<th>curValor</th>
<th>intid</th>
<th>CurValor</th>
<th>str_CIDADE</th>
<th>Bairro</th>
<th>Opção</th>
</tr>
</thead>
<tbody>
<tr role="row" class="odd">
<th></th>
<th>Foto</th>
<th>ID Historico</th>
<th>curValor</th>
<th>intid</th>
<th>CurValor</th>
<th>str_CIDADE</th>
<th>Bairro</th>
<th></th>
</tr>
</tbody>
</table>
The column that I will display the photo is: Photo
The Datatables Javascript is:
/// abreviação
"processing": true,
"serverSide": false,
"ajax": {
"url": "grid3.ashx"
},
columns: [
{
"className": 'details-control',
"orderable": false,
"data": null,
"defaultContent": ''
},
{
"className": '',
"orderable": false,
"data": null,
"defaultContent": ' <img class="img-thumbnail " src="http://imgteste.wmb.com.br//tb/" style="width:50px;" />'
},
{ data: 'IDHistorico' },
{ data: 'curValor' },
{ data: 'intid' },
{ data: 'curValor' },
{ data: 'str_CIDADE' },
{ data: 'str_BAIRRO' }
///abreviação do código
The line is this: "defaultContent": ''
Summary: I am trying to recover the value of JSON and put in this script that initializes Datatables.net, the field I am trying is the name of the photo I tried to create:
var data = table.row( $(this).parents('tr') ).data();
and call as date[8] //9th json record, but it didn’t work
Uncaught Typeerror: Cannot read Property '8' of Undefined
If date is
undefined
, JSON doesn’t even get to the datatable. First you need to fix this.– Leonel Sanches da Silva
if I remove this attempt to use the returned json in the Datatable itself it displays and grid correctly. I think I’ll edit my question to be more objective
– Dorathoto