rowGroup endRender multiple Rows
rowGroup endRender multiple Rows
EdaurdoCR
Posts: 2Questions: 1Answers: 0
Can you add two rows at the end?, since it only returns only one and I occupy two.
rowGroup: {endRender: function(rows, group) {
var intVal = function(i) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '') * 1 :
typeof i === 'number' ?
i : 0;
};
var column = [6, 7, 8, 9];
var api = rows,
data;
var numero = $.fn.dataTable.render.number(',', '.', 2).display;
var container = $('<tr/>');
container.append('<td colspan="6" style="text-align:right;">Total en pesos</td>');
_.each(column, function(idx) {
var totalPesos = api
.column(idx)
.data()
.reduce(function(a, b) {
var cur_index = api.column(idx).data().indexOf(b);
if (api.column(5).data()[cur_index] != "Dolares") {
return intVal(a) + intVal(b);
} else {
return intVal(a);
}
}, 0)
container.append('<td>' + numero(totalPesos) + '</td>');
})
container.append('<td colspan="6" style="text-align:right;">Total en dolares</td>');
_.each(column, function(idx) {
var totalDolares = api
.column(idx)
.data()
.reduce(function(a, b) {
var cur_index = api.column(idx).data().indexOf(b);
if (api.column(5).data()[cur_index] != "Pesos") {
return intVal(a) + intVal(b);
} else {
return intVal(a);
}
}, 0)
container.append('<td>' + numero(totalDolares) + '</td>');
})
return $(container)
},
dataSrc: 'estado'
}
This question has an accepted answers - jump to answer
Answers
You are in control of what HTML elements are returned. Currently you are building one
tr
in the container variable. You can add anothertr
for two rows.Kevin
Thank you very much, I never thought that.
Okay but how? If the API requires you to return a row, how do you do this?
@tnk479 Try something like this example:
http://live.datatables.net/fudimora/1/edit
Kevin