I guess the solution is again very simple (or not feasible at all), let’s see.
I want to display a list of upcoming birthdays and upcoming jubilees. Both data fields contain the dates with the birth year respectively the year of the event for the jubilee.
Having an LFD, I want to show only the next 6 birthdays, but I simply chose a birthdate - greater than today obviously it takes the year into account and the resulting list is empty.
You can achieve your goal by using the following code. Put this code in the javascript tab of the screen where you are showing the LFD.
Fliplet.Hooks.on('flListDataBeforeRenderList', function(options) {
let number_of_upcoming_birthdays_to_display = 6;
options.records.forEach(function(row) {
var birthday = moment(row.data.Birthday);
var today = moment().format('YYYY-MM-DD');
var age = moment(today).diff(birthday, 'years');
moment(age).format('YYYY-MM-DD');
var nextBirthday = moment(birthday).add(age, 'years');
moment(nextBirthday).format('YYYY-MM-DD');
nextBirthday = moment(birthday).add(age + 1, 'years');
row.data['difference'] = nextBirthday.diff(today, 'days');
});
options.records.sort(function(a, b) {
return a.data.difference - b.data.difference;
});
options.config.limitEntries = number_of_upcoming_birthdays_to_display;
options.config.enabledLimitEntries = true;
});
You can notice the second line of code “let number_of_upcoming_birthdays_to_display = 6;”
You can change the 6 to your preferred choice of entries, you want to show on the page. For example, changing it to 10 will show you the top 10 upcoming birthdays.
One other thing is that I assumed the field name is Birthday. In case you have a different name for the field. You can change the following line of code from
var birthday = moment(row.data.Birthday);
to
var birthday = moment(row.data.changedfieldname);
You can notice that the Birthday text in the code is changed to changedfieldname.
I hope this information will help you. Below is the screenshot of the code and output.