I've a table with this columns: name, age, birthday I also have a input field with date.
birthday is populated with a date. I want to create 2 buttons like "select users with age > 30" and "select user with age > 60".
var table= $('#users').DataTable({
"drawCallback": updateDays(moment()),
paging: false,
columnDefs: [ {
orderable: false,
className: 'select-checkbox',
targets: 0
} ],
select: {
style: 'multi'
},
order: [[ 1, 'asc' ]],
buttons: [{'selectAll',
'selectNone',
],
[...]
$('input[id="dateOfBirthday"]').daterangepicker({
"autoApply": true,
"singleDatePicker": true,
"showDropdowns": true,
locale: {
format: 'DD-MM-YYYY'
}
}, function(start, end, label) {
updateDays(start);
$('input[id="dateOfBirthday"]').val(start.format("DD-MM-YY"));
});
And when you change the date, it update the years inside the table
function updateDays(startDate) {
$('.age').each(
function () {
var diff;
var start;
start = $(this).closest('tr').children('.birthday').text();
start= moment(start, "DD/MM/YY");
diff = startDate.diff(start, 'days');
$(this).text(diff);
});
[...]
The code is adapted from the real project because it's too long so please understand if there are some coding errors; what it's important here is the logic behind the code, not the code itself.
Thanks