AUTHOR: Peter Milchev
DATE POSTED: September 25, 2018
Create a custom Time Marker similar to the Current Time Marker in the Gantt - Current Time Marker demo.
We will use an implementation similar to the one the Gantt uses internally for the Current Time Marker. Once we create the renderLine function, we should call it in the OnClientDataBound event of the Gantt.
In the following example, we use the CSS class .k-status-line for the new line element, and use this class to style it.
<
style
>
.RadGantt .k-status-time {
background-color: blue;
position: absolute;
}
</
<script type=
"text/javascript"
function
OnClientDataBound(sender, args) {
//https://stackoverflow.com/a/563442
// implement addDays method for demonstration purposes
Date.prototype.addDays =
(days) {
var
date =
new
Date(
this
.valueOf());
date.setDate(date.getDate() + days);
return
date;
statusLineDate =
Date().addDays(-1);
renderLine(sender, statusLineDate)
renderLine(gantt, date) {
ganttView = gantt._widget.view();
currentTime = date;
timeOffset = ganttView._offset(currentTime);
element = $(
'<div class=\'k-status-time\'></div>'
);
viewStyles = kendo.ui.GanttView.styles;
tablesWrap = $(
"."
+ viewStyles.tasksWrapper);
tasksTable = $(
+ viewStyles.tasksTable);
slot;
if
(!ganttView.content || !ganttView._timeSlots().length) {
;
ganttView.content.find(
'.k-status-time'
).remove();
slot = ganttView._timeSlots()[ganttView._slotIndex(
'start'
, currentTime)];
(currentTime < slot.start || currentTime > slot.end) {
(tablesWrap.length && tasksTable.length) {
timeOffset += tasksTable.offset().left - tablesWrap.offset().left;
element.css({
left: timeOffset +
'px'
,
top:
'0px'
width:
'1px'
height: ganttView._contentHeight +
}).appendTo(ganttView.content);
</script>
telerik:RadGantt
runat
=
"server"
ID
"RadGantt1"
OnClientDataBound
"OnClientDataBound"
SnapToGrid
"false"
SelectedView
"WeekView"
DataBindings
TasksDataBindings
IdField
"ID"
TitleField
"Title"
StartField
"Start"
EndField
"End"
PercentCompleteField
"PercentComplete"
OrderIdField
"OrderID"
SummaryField
"Summary"
ParentIdField
"ParentID"
/>
DependenciesDataBindings
PredecessorIdField
"PredecessorID"
SuccessorIdField
"SuccessorID"
TypeField
"Type"
protected
void
Page_Load(
object
sender, EventArgs e)
{
RadGantt1.DataSource = GetGanttTasksSource();
private
DataTable GetGanttTasksSource()
DataTable dataTable =
DataTable();
dataTable.Columns.Add(
DataColumn(
typeof
(
int
)));
string
(DateTime)));
decimal
"Expanded"
bool
dataTable.PrimaryKey =
DataColumn[] { dataTable.Columns[
] };
parentsCount = 4;
for
i = 1; i <= parentsCount; i++)
DataRow row = dataTable.NewRow();
row[
] = i;
] = DBNull.Value;
] =
"Task #"
+ (i);
] = DateTime.Now.AddDays(i - 1);
] = DateTime.Now.AddDays(i);
] = 0.2M;
(i == parentsCount)
false
else
] = i == parentsCount;
// last task is a parent/summary
dataTable.Rows.Add(row);
i = parentsCount + 1; i <= parentsCount + 5; i++)
] = parentsCount;
] = 0.4M;
dataTable;
Resources Buy Try