Filter Dates In Table From, To
I have table in my project I have filtering by date in my table Now it filters only by Date from value, but I want to filter it from-to dates. How I can do this in my case? Here is
Solution 1:
Please check if this is ok
functionfilterRows() {
varfrom = $('#datefilterfrom').val();
var to = $('#datefilterto').val();
if (!from && !to) { // no value for from and toreturn;
}
from = from || '1970-01-01'; // default from to a old date if it is not set
to = to || '2999-12-31';
var dateFrom = moment(from);
var dateTo = moment(to);
$('#testTable tr').each(function(i, tr) {
var val = $(tr).find("td:nth-child(3)").text();
var dateVal = moment(val, "DD/MM/YYYY");
var visible = (dateVal.isBetween(dateFrom, dateTo, null, [])) ? "" : "none"; // [] for inclusive
$(tr).css('display', visible);
});
}
$('#datefilterfrom').on("change", filterRows);
$('#datefilterto').on("change", filterRows);
Post a Comment for "Filter Dates In Table From, To"