RowGroup - getting a value from another column in the first row
RowGroup - getting a value from another column in the first row
I know this has to be simple, but all the examples I see are very complex.
In my rowGroup, I want to use startRender to output the group data point, and append string value in another column (second column, RevenueTypeCode) from the first row of the group. Or any row in the group - they will all be the same.
I've tried many, many things.
I am using an object (mydata.revenue), not an array.
How do I get the value from another column in the first row of the group in startRender?
Thanks!
$('#revenue').DataTable({
data: mydata.revenue,
paging: false,
ordering: false,
dom: 'tp',
orderFixed: [[0,'asc']],
rowGroup: {
dataSrc: "RevenueType",
startRender: function (rows, group) {
**var code = <<Need string in second column (RevenueTypeCode)>>;**
return group + code;
}
},
columns: [
{
data: 'RevenueType',
render: (data, type, row) => {
return "";
}
},
{ data: 'RevenueTypeCode' },
{ data: 'RevenueAmt' }
]
});
Answers
The
rowGroup.startRender
docs outline all of the parameters available to the function. Therows
parameter contain all of the rows for the group. You can get the value of the first with with something likerows[0].RevenueTypeCode
.Kevin
Kevin,
Believe me, I've combed through the docs and many examples, and tried all sorts combinations.
The example you gave,
rows[0].RevenueTypeCode
returns "undefined", which then makesrows[0].data.RevenueTypeCode
undefined (Javascript error - cannot read properties of undefined).When I set a breakpoint on the startRender function, the Chrome debugger appears to show rows[] has the values 0, 1, and 2 (there are 3 rows in the row group). But I don't see any other data.
Gotta be something obvious I'm missing if it is supposed to work.
Right, sorry I forgot about that. That is the row index. You need to use
row().data()
to get the data. Something like this:Maybe @allan or @colin would be willing to provide clarification around this in the docs. I forget every time until someone like you reminds me that its not the rows but the row indexes
Kevin
Well.. I had some dinner and went fishing... and when I got back I tried a few things and got it to work...
rows.data()[0].RevenueTypeCode
I think I tried every combination of rows/row/data/[0]/(0) possible...