Completed
Last Updated: 12 May 2021 12:57 by ADMIN
Release R2 2021
ADMIN
Peter Milchev
Created on: 19 Mar 2018 14:35
Category: Gantt
Type: Feature Request
1
Allow templates for HeaderDateFormat in RadGantt

Currently, the RadGantt allows only format strings as a value for the WeekHeaderDateFormat property. For example, allowing a template similar to Kendo Gantt:

Use case - show week number instead of the dates. Workaround to show week number: The suggestion is based on the https://demos.telerik.com/aspnet-ajax/gantt/examples/accessibility-and-internationalization/localization/defaultcs.aspx demo. What you should add to the Gantt markup declaration is the WeekView-WeekHeaderDateFormat="dd/MM/yyyy" and OnClientDataBound="OnClientDataBound" properties. // https://stackoverflow.com/questions/6117814/get-week-of-year-in-javascript-like-in-php function getWeekNumber(d) { // Copy date so don't modify original d = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate())); // Set to nearest Thursday: current date + 4 - current day number // Make Sunday's day number 7 d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7)); // Get first day of year var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1)); // Calculate full weeks to nearest Thursday var weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7); // Return array of year and week number // return [d.getUTCFullYear(), weekNo]; return weekNo } function OnClientDataBound(sender, args) { if (sender.get_viewsData()[sender.get_selectedView()].type == "week") { $telerik.$('.rgtTimelineWrapper thead>tr:first .radHeader', sender.get_element()).each(function (index) { var $this = $(this) var datestring = $this.text().substring(0, 10); var date = new Date(datestring); var weekNumber = getWeekNumber(date) $this.text("Week " + weekNumber) }) } }

1 comment
ADMIN
Peter Milchev
Posted on: 12 May 2021 12:57

Hello,

The R2 2021 release allows customizing the headers with a template now:

Regards,
Peter Milchev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.