Starting from datatables-row_grouping
I have a business requirement to format a datatable where results are grouped by 2 columns.
This is what I have for my datatable config which does produce results close to what I need, however I can't get the value of the second column.
The api.column(1 below is referencing the first column, i need column two (2) as well. I tried columns([1, 2] and expected to get an array of results for .each() but that was a failure.
var dtOptions = {
"dom": '<"clearfix"><"pull-left"l><"pull-right"Bf>r<"horizontal-scroll"t><"pull-left"i><"pull-right"p><"clearfix">',
"pageLength": 10,
"paging": true,
"columnDefs": [
{
"targets": groupCols, /// this is an array [1, 2]
"visible": false
}],
"order": [[1, 'asc']],
"displayLength": 15,
"drawCallback": function ( settings ) {
var api = this.api();
var rows = api.rows( {page:'current'} ).nodes();
var last = null;
api.column(1, { page: 'current' }).data().each(function (group, i) {
if (last !== group) {
$(rows).eq(i).before(
'<tr class="group"><td colspan="3">' + group + '</td><td colspan="14">' + need_second_column_string_here + '</td></tr>'
);
last = group;
}
});
}
}
Thanks for any assistance.