Calendar - add/support Enabled Dates
I'm submitting a ... (check one with "x")
[ ] bug report => Search github for a similar issue or PR before submitting
[x] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35
Current behavior Currently, you cannot provide a list of dates that are the only enabled dates on the Calendar control
Expected behavior Provide a list of enabled dates, and all other dates would be disabled
What is the motivation / use case for changing the behavior? Provide a way of showing the calendar with only the dates that have data enabled. In my case i have an average of 3 days enabled and the rest of the year disabled. So it's also a perfomance and legibility issue.
This issue is the same that https://github.com/primefaces/primeng/issues/3712 I'd like to attach a PR, so I think I have to file an issue again.
If there is more demand, we'll go ahead.
I would need that feature, too. Are there any plans to implement it?
I would need this feature too. In a scenario where you have a datatable and a date filter column, you would expect to be able to filter only on the enabled days (so those dates for which is data in the table for a given date). Setting the enabled dates would then make more sense than looping & setting all possible disabled dates.
I need that too
Same for me. Definitely need this feature.
This missing feature is preventing me to use this library. Is there any workaround? We have an item ordering feature, where we select the delivery dates, but only the ones that are allowed.
If people are still seeking a fix until this is a feature, here's a workaround I did. Somewhere in the startup of your app, create a method called "installHacks()" or such, and in there, put the following:
public installHacks() {
Calendar.prototype["enabledDaysCache"] = [];
Calendar.prototype["setEnabledDates"] = function(dates:Date[]):void {
try {
this.enabledDaysCache = [];
for (let eDate of dates) {
this.enabledDaysCache.push(eDate.getFullYear() + ":" + eDate.getMonth() + ":" + eDate.getDate());
}
}
catch (err) {
console.error(err);
}
}
// ensure the part below "original code" matches the source function in the GitHub for PrimeNG Calendar that you're using
// current source: https://github.com/primefaces/primeng/blob/master/src/app/components/calendar/calendar.ts
Calendar.prototype.isDateDisabled = function(day:number, month:number, year:number):boolean {
if (this.enabledDaysCache && this.enabledDaysCache.length > 0) {
try {
return !this.enabledDaysCache.includes(year + ":" + month + ":" + day);
}
catch (err) {
console.error(err);
}
}
// original code
if (this.disabledDates) {
for (let disabledDate of this.disabledDates) {
if (disabledDate.getFullYear() === year && disabledDate.getMonth() === month && disabledDate.getDate() === day) {
return true;
}
}
}
return false;
}
}
So we created a holder called enabledDaysCache. As we can't create a bindable property (if you need that, add the necessary code and inject, assuming you can get the compiler to accept it).
Where you are using the calendar, give it a #name and fetch it via:
@ViewChild('myCalendar', {read: Calendar}) myCalendar: Calendar;
Then in afterViewInit or similar you'd do this:
this.myCalendar.disabledDates = [new Date()]; // forces all the regular checks to see if dates are disabled to happen
this.myCalendar["setEnabledDates"](yourListOfDates);
this.cd.markForCheck();
This essentially disables every date by default, unless it's in the enabledDays array.
Hi,
So sorry for the delayed response! Improvements have been made to many components recently, both in terms of performance and enhancement. Therefore, this improvement may have been developed in another issue ticket without realizing it. You can check this in the documentation. If there is no improvement on this, can you reopen the issue so we can include it in our roadmap? Please don't forget to add your feedback as a comment after reopening the issue. These will be taken into account by us and will contribute to the development of this feature. Thanks a lot for your understanding!
Best Regards,
Hi,
So sorry for the delayed response! Improvements have been made to many components recently, both in terms of performance and enhancement. Therefore, this improvement may have been developed in another issue ticket without realizing it. You can check this in the documentation. If there is no improvement on this, can you reopen the issue so we can include it in our roadmap? Please don't forget to add your feedback as a comment after reopening the issue. These will be taken into account by us and will contribute to the development of this feature. Thanks a lot for your understanding!
Best Regards,
I would need that feature, too. Are there any plans to implement it?