I want to change the colors of tasks in a timeline that I have. Can this be done? How?
Thanks you!
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityTo manually change event/callout colors in a timeline or project summary:
The font color obviously will change the color of the text identifying a task. For tasks with a start and end date that show as a bar, the paint bucket changes the fill color of the task. For callouts (events with only a start OR due date) the paint bucket changes the color of the line connecting the callout text to the timeline.
Note that if you have a project summary associated with the task list, changing the colors of the task list will also affect the project summary (and vice versa).
For the people who is looking for change the timeline color based on status, use the following code.
<script src="http://code.jquery.com/jquery-1.10.2.js" type="text/javascript"></script>
<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("updateColors");
setTimeout(
function updateColors() {
debugger;
$(".ms-tl-mainArea .ms-tl-barTitle").each(function () {
var taskStatus = getTaskStatus($(this).text());
if (taskStatus == "Raised") {
$(this).parent().css("background-color", "#FFBF00");
}
if (taskStatus == "In Progress") {
$(this).parent().css("background-color", "green");
}
if (taskStatus == "Completed") {
$(this).parent().css("background-color", "blue");
}
});
}, 5000);
function getTaskStatus(taskname) {
debugger;
var status = "";
var nameIndex = 0;
var statusIndex = 0;
//get Task Name column index and Task Status column index
$(".ms-listviewtable tr th").each(function (i) {
if ($(this).find("a").text() == "InitiativeName") {
nameIndex = i;
}
if ($(this).find("a").text() == "Status") {
statusIndex = i;
}
});
$(".ms-listviewtable tr").each(function (i) {
if (i > 0) {
var name = $(this).children("td").eq(nameIndex).text();
if (name == taskname) {
status = $(this).children("td").eq(statusIndex).text();
}
}
});
return status;
}
</script>
In order to get the column index for task name and task status, it´s needed to change the find("a") or "InitiativeName" parameters?
Same case for children("td") and eq(nameIndex)/eq(statusIndex).
Thanks a lot for you help.