I have the following table generated with Datatables:
Now, inside the Prize column, I want to create a regular table (without datatables), the way I do it is by calling a function called insertTablePositionDraw;
"columns": [
{
"data": "prize_money",
"name": "draws.prize_money",
"mRender": function (data, wea, row, meta) {
return row.prize_money
? '$<strong>' + data + ' </strong>' +
'<i class="fa fa-bar-chart create-prize-money" aria-hidden="true" data-toggle="modal" data-target="#modalCreatePrizeMoney"></i>' +
'<br/>' + (row.positions != "" ? insertTablePositionDraw(row.positions) : '')
: '';
}
},
]
The called function is the following:
function insertTablePositionDraw(data){
return '<table class="table table-bordered">' +
'<thead>'+
'<tr>' +
'<th class="text-center">Posición</th>' +
'<th class="text-center">Premio</th>' +
'</tr>' +
'</thead>'+
'<tbody>'+
$.each(data, function(index, item){
`<tr>`+
`<td>`+
data.position;
`</td>`+
`<td>`+
data.pivot.dato;
`</td>`+
`</tr>`
})
'</tbody>'
'</table>'
}
in this way it does not create the table correctly, it does not show me the data
Errors in the post:
'
and"
but not`
).return
or write it to some element or something).each
doesn't work for concatenation (you should create an auxiliary string and fill it before, inside and after theeach
).data
is being misused within theeach
(you should dodata[index]
or useitem
to accessposition
orpivot
).Here you can see the errors in your code with comments:
Correcting that, the result looks like this and it works: