render into for loop

render into for loop

passasoozpassasooz Posts: 2Questions: 0Answers: 0

Hi all, I'm a new user on this platform and this is my first discussion.
I would ask if is possible create a render foreach time into a for loop.
For example:

Here I'm out of the datatable.

for(i=0; i<(diffDays); i++){
var data_formattata = moment(new_data_from).add(i, 'days');
var header = data_formattata.format("YYYY-MM-DD");
clmns.push({
"sTitle": data_formattata.format("DD-MM-YYYY"),
"mData": {header:header},
render:function(data,type,row){
var tmp = '<a role="button" onclick="aggiungiDisponibilita('+header+','+data['id']+')" class="btn btn-sm btn-success" title="Aggiungi" data-tooltip="tooltip"><i class="fa fa-plus"></i></a>';
return tmp;
}
});
}

Now I'm into the datatable

$('#datatable').DataTable({
processing:true,
serverSide:true,
ajax: {
url:"{!! url('/ajax-lista-disponibilita-staff/') !!}",
data:function(d){
d.data_from = moment(new_data_from).format("YYYYMMDD"),
d.data_to = moment(new_data_to).format("YYYYMMDD")
}
},
type:'GET',
columns: clmns,

so where is my problem? my problem is that my variable "header" located into the render function is assumed the last value of the loop for instead the value of each cycle.

How can I solve that?

Replies

  • PaulusPaulus Posts: 69Questions: 17Answers: 5

    Not the problem, but what do you want to do? What type of table or column are you trying to create?

  • passasoozpassasooz Posts: 2Questions: 0Answers: 0

    I want a dynamic table and I had it, the column are ok, all the table is ok, but the render that i do into the loop for is not ok because I cannot import on it the title of the single cell, or better the header of the single cell.

This discussion has been closed.