RadMonthYearPicker - Show only the current year

3 Answers 17 Views
MonthYearPicker
Bob
Top achievements
Rank 1
Iron
Iron
Bob asked on 04 May 2025, 01:39 AM

Hi,

I'm following the setup for "RadMonthYearPicker" with the link below: 

https://demos.telerik.com/aspnet-ajax/monthyearpicker/overview/defaultcs.aspx

My need is to show only the current year (2025). In this case Year 2021-2024 and 2026-2030 should be hidden or removed from the popup.

Is there a property to do so? Or is there a workaround?

 

Thanks,

Bob

3 Answers, 1 is accepted

Sort by
0
Vasko
Telerik team
answered on 05 May 2025, 09:27 AM

Hi Bob,

To achieve the functionality of displaying only the current year (2025) in the RadMonthYearPicker, you can use client-side code to manipulate the popup content, as there is no direct property to limit the years displayed. For that, you can utilize the OnPopupOpening event, get all the items inside the popup, and hide the years that are not the current one: 

<telerik:RadMonthYearPicker ID="RadMonthYearPicker1" runat="server">
    <ClientEvents OnPopupOpening="onPopupOpening" />
</telerik:RadMonthYearPicker>
function onPopupOpening(sender, args) {
    setTimeout(() => {
        let pickerItems = document.querySelectorAll(".RadCalendarFastNavPopup td a");

        pickerItems.forEach((item) => {
            let itemText = item.innerHTML;
            let itemValue = parseInt(itemText);

            if (!isNaN(itemValue) && itemValue !== 2025) {
                item.style.display = 'none'; // Hide the years that are not 2025
            }
        });
    }, 100);
}

This approach should help you achieve the desired functionality. Try it and see if it will work for your case.

    Regards,
    Vasko
    Progress Telerik

    Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
    0
    Bob
    Top achievements
    Rank 1
    Iron
    Iron
    answered on 06 May 2025, 03:18 PM

    Hi Vasko,

    That was a great workaround. With that client event, I was able to hide other years. However the year 2025 button is rendered in the bottom of the popup. How can the year 2025 be rendered in the first row? Possible?

     

    Vasko
    Telerik team
    commented on 07 May 2025, 07:40 AM

    Hi Bob,

    You can manually append the cell with the current year to the first row by targeting it:

    function onPopupOpening(sender, args) {
        setTimeout(() => {
            let pickerItems = document.querySelectorAll(".RadCalendarFastNavPopup td a");
    
            pickerItems.forEach((item) => {
                let itemText = item.innerHTML;
                let itemValue = parseInt(itemText);
    
                if (!isNaN(itemValue) && itemValue !== 2025) {
                    item.parentElement.style.display = 'none'; // Hide the years that are not 2025
                }
    
                if (itemText === "2025") {
                    let firstRow = item.parentElement.closest("tbody").querySelector("tr"); // Find the first row of the Picker
                    firstRow.appendChild(item.parentElement);
                }   
            });
        }, 10);
    }
    

    Regards,
    Author nickname
    Progress Telerik

    0
    Bob
    Top achievements
    Rank 1
    Iron
    Iron
    answered on 07 May 2025, 04:31 PM

    Brilliant! Appreciated your help!

     

    Thanks,

    Bob

    Tags
    MonthYearPicker
    Asked by
    Bob
    Top achievements
    Rank 1
    Iron
    Iron
    Answers by
    Vasko
    Telerik team
    Bob
    Top achievements
    Rank 1
    Iron
    Iron
    Share this question
    or