How to order in a "row grouping" by date?
How to order in a "row grouping" by date?
PatricioFink
Posts: 27Questions: 12Answers: 0
From: https://datatables.net/examples/advanced_init/row_grouping.html
I have a table where i'm grouping by date:
http://s9.postimg.org/6dkbxsibz/Capture.jpg
but when i try to order by that grouping row, it gets ordered by the TIME and not the DATE:
http://s24.postimg.org/c8n1cu2c5/Capture.jpg
This is my script:
$(function () {
var table = $('#VentasLocacion').DataTable({
"columnDefs": [
{ "visible": false, "targets": 0 }
],
"order": [[0, 'desc']],
"displayLength": 100,
"drawCallback": function (settings) {
var api = this.api();
var rows = api.rows({ page: 'current' }).nodes();
var last = null;
api.column(0, { page: 'current' }).data().each(function (group, i) {
if (last !== group) {
$(rows).eq(i).before(
'<tr class="group"><td colspan="7"><b>' + "Fecha de venta: " + '</b>' + group + '<b>' + " Cliente: " + '</b>' + rows[i].children[3].innerText + '</td></tr>'
);
last = group;
}
});
}
});
// Order by the grouping
$('#VentasLocacion tbody').on('click', 'tr.group', function () {
var currentOrder = table.order()[0];
if (currentOrder[0] === 2 && currentOrder[1] === 'asc') {
table.order([2, 'desc']).draw();
}
else {
table.order([2, 'asc']).draw();
}
});
});
This discussion has been closed.