RowGroup loop all TD cells
RowGroup loop all TD cells

Hi, I need to loop all TD cells when a rowGroup is enable. I need to read a data-xxx attribute from each cell to estabilish if I need to sum or subtract.
I tried this code but I get error in console.
<tr>
<td>LONDON</td>
<td data-typecell="sum">10</td>
</tr>
<tr>
<td>LONDON</td>
<td data-typecell="subtract">3</td>
</tr>
<tr>
<td>LONDON</td>
<td data-typecell="sum">5</td>
</tr>
<tr>
<td>NY</td>
<td data-typecell="sum">50</td>
</tr>
rowGroup: {
enable: true,
startRender: null,
endRender: function ( rows, group ) {
var rowsToCheck = rows.data().pluck(1); // <---- column index 1
var sum = 0;
$(rowsToCheck).each(function(index, value) {
var typeCell = $(this).data("typecell");
var value = parseFloat($(this).html()) || 0;
if (typeCell == "sum" ) {
sum = sum + value;
} else {
sum = sum - value;
}
});
return $('<tr/>')
.append( '<td>Totals '+group+'</td>' )
.append( '<td class="text-right">'+sum.toFixed(2)+'</td>' )
.append( '<td/>' );
},
dataSrc: 0
},
...
Any suggest? Thanks
This discussion has been closed.
Replies
What error?
Error: TypeError: t is undefined
Not sure if your code is actually going to retrieve the data attribute. Its not obvious why you would get the TypeError. Please put together a test case so we can help you workout what you want to do.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Ok this is my fiddle after some edits. Still waiting for a solution
http://live.datatables.net/wenocuho/1/edit
Result expected written after the table
Hi @itajackass ,
You've just got a solution in a few hours of posting, I'd say that was pretty good service! As we always say, post a test case upfront, you'll get faster and more accurate responses.
Cheers,
Colin
Hi @colin , sorry i don't want to say "waiting" but i wanted to wrote "looking"
I don't know how to loop inside grouped rows, and for each row of it, manipulate the (n)-td with jquery to read attributes etc...
Did you see I posted the solution in my response?
Ops i don't seen it! Thank you! It works like a charm!!