This is a migrated thread and some comments may be shown as answers.

Colorize Tasks

1 Answer 86 Views
Gantt
This is a migrated thread and some comments may be shown as answers.
Valerius
Top achievements
Rank 1
Valerius asked on 23 Nov 2017, 08:19 AM

Hi Admins, is there any possible to Colorize Tasks in gantt [PHP] FOR EXAMPLE:

 <script>
      function onDataBound() {
        var gantt = this;

        gantt.element.find(".k-task").each(function(e) {
          var dataItem = gantt.dataSource.getByUid($(this).attr("data-uid"));

          // colorize task per business requirements
          if (dataItem.id = 904) {
            this.style.backgroundColor = "#f99";
          } else {
            this.style.backgroundColor = "#9f9";
          }
        });
      }
</script>

 

But this dosen't work in php gantt, can you please help, and tell what is the way to get colored tasks depending on values for example:

 

$idField = new \Kendo\Data\DataSourceSchemaModelField('id');
$idField->type('number')
        ->from('ID')
        ->nullable(true);

 

Thanks

1 Answer, 1 is accepted

Sort by
0
Veselin Tsvetanov
Telerik team
answered on 27 Nov 2017, 08:08 AM
Hi Valerius,

The approach, that you have chosen to alter the Gantt Task background color depending on the Task ID is appropriate. Only a small change in the implementation is needed in order to execute the dataBound handler properly:
function onDataBound() {
  var gantt = this;
  gantt.element.find(".k-task").each(function(e) {
    var dataItem = gantt.dataSource.getByUid($(this).attr("data-uid"));
     
    // colorize task per business requirements
    if (dataItem.id === 904) {
      this.style.backgroundColor = "#f99";
    } else {
      this.style.backgroundColor = "#9f9";
    }
  });
}

Also, do not forget to attach the event handler explicitly:
$gantt
    ->dataBound("onDataBound")
?>

Regards,
Veselin Tsvetanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Gantt
Asked by
Valerius
Top achievements
Rank 1
Answers by
Veselin Tsvetanov
Telerik team
Share this question
or