Im trying to filter the directors $inactiveDirectors who were active during the selected fromDate and the toDate.
Directors will be active from their effective date (director.effective_date) to their resigned/removed date (director.release_date). And if the user did not pick a toDate it will be assumed to as the current date.
The function:
function loadDirectors() {
return {
fromDate: ""
, toDate: ""
, fromDateObj: null
, toDateObj: null
, directorsList: @json($inactiveDirectors)
, get filteredDirectors() {
if (this.fromDate === "") {
return this.directorsList;
}
this.fromDateObj = new Date(this.fromDate);
if (this.toDate === "") {
this.toDateObj = null;
} else {
this.toDateObj = new Date(this.toDate);
}
return this.directorsList.filter((director) => {
let effective_date_obj = new Date(director.effective_date);
let release_date = new Date(director.release_date);
if (this.fromDateObj.getTime() < effective_date_obj.getTime()) {
if (this.toDateObj) {
if (this.toDateObj.getTime() > release_date.getTime()) {
return director;
} else {
return director;
}
}
}
});
}
}
}
I've been trying to filter using Alpine.js with no luck yet. Appreciate if you could find a way to resolve this.
Thank you
