How do I use my own field name in dhtmlxGantt

Hi all,

How do I use my own field name in dhtmlxGantt?

I have a column name original_duration that I want to display as duration in dhtmlxGantt, but whenever I replace the “duration” with “original_duration” it give me 1 as the duration.

$connector->render_table("tasks", "taskid", "original_startdate, duration,taskname, progress,projectid");

This code is ok and output the correct duration based on column named duration in database.

$connector->render_table("tasks", "taskid", "original_startdate, original_duration,taskname, progress,projectid");

But this code, output the duration as 1 instead of the actual value (which is 7).

Its kinda weird because for “original_startdate”, the value is correct.

Thanks in advance for the help. :smiley:

Hi,
check this topic, there is an updated version of the connector attached. Does it solves the problem?
viewtopic.php?f=15&t=38290

Hi aliaksandr,
thanx for the reply.

Sorry but I dont quite understand the solution.

So the solution is just to use attribut_xxx(fieldname) is it?

Oops…sorry I didn’t notice the connector part. Already update my connector to the one provided. And it still didn’t solve my problem

Hi aliaksandr,

This is to inform you I already made it. Thanx for the help! :slight_smile:

I understand the column alias wrongly.

It should be db_column_name(dhtmlxgantt_field)

In my case it will be original_duration(duration)

Thanks for the help yeah!! :smiley:

whoopss… its not fixed yet… im just too exaggerated to see the data is correct but it appeared that its taking the duration field. :frowning:

How eh?

Hi,
i’ve renamed ‘duration’ column to ‘original_duration’ in my local database (used sql dump from the samples folder, table gantt_tasks)
Following configuration seems to work

$gantt->render_table("gantt_tasks","id","start_date,original_duration(duration),text,progress,parent","");

Note that on the client-side the duration and several other mandatory properties will be always named as expected by the gantt (start_date, duration, end_date, etc.) instead of names specified in the database

Please try to update connectors from github
Latest version contains the fix for very similar issue.

github.com/dhtmlx/connector-php

Still the same. Not happening. It still taking the duration value from the database instead of original_duration.

And if I changed the database to current_duration, duration become 1 for all.

As for information, I’m using CakePHP.

Here is my code for the data.

$connector = new JSONGanttConnector($this->Task, "PHPCake");
		// $connector->filter("projectid","6");
		$connector->render_table("tasks", "taskid", "original_startdate,current_duration(duration),taskname, progress,projectid,original_duration");

The best I can be is to change the data manually in onTaskLoading event, the data is changed, but the gantt is not refresh. Maybe you guys can help with this.

Here is the code for onTaskLoading

gantt.attachEvent("onTaskLoading", function(task){
	    if (task.projectid == projectid){
	    	task.duration = parseInt(task.original_duration);
	        return true
	    }
	    else
	    	return false;
	});

Update.

When I changed the duration, the duration text in the task list is updated. But not the gantt bar… Any idea on how to refresh the gantt bar also?

I can confirm - in case of Cake PHP, handling of names is really invalid
Please try to use the attached php file instead of the existing one.
gantt_connector.zip (3.02 KB)

Still the same stanislav,

Here is my full code in CakePHP.

The script in view

<script type="text/javascript">
    var webroot = "<?php echo $this->webroot; ?>";
    var projectid = "<?php echo $mProject['Project']['projectid']; ?>";
    gantt.config.xml_date="%Y-%m-%d %H:%i";
    gantt.config.show_progress = false;
    gantt.config.readonly = true;
    gantt.attachEvent("onTaskLoading", function(task){
	    if (task.projectid == projectid){
	    	// task.duration = parseInt(task.original_duration); //change the duration
	        return true
	    }
	    else
	    	return false;
	});
	gantt.init("gantt_here");
	gantt.load(webroot + "timeline/gantt_data_original");
</script>

The data in controller

public function gantt_data_original(){                                               
        $this->autoRender = false;

	$connector = new JSONGanttConnector($this->Task, "PHPCake");
	$connector->render_table("tasks", "taskid", "original_startdate,original_duration(duration),taskname, progress,projectid,original_duration");                                          
    }

The database data

The resulting gantt view

Now if I changed the script a bit by implementing the change of duration with original duration as below.

The script

<script type="text/javascript">
    var webroot = "<?php echo $this->webroot; ?>";
    var projectid = "<?php echo $mProject['Project']['projectid']; ?>";
    gantt.config.xml_date="%Y-%m-%d %H:%i";
    gantt.config.show_progress = false;
    gantt.config.readonly = true;

    gantt.attachEvent("onTaskLoading", function(task){
	    if (task.projectid == projectid){
	    	task.duration = parseInt(task.original_duration); // [b]I implement this[/b]
	        return true
	    }
	    else
	    	return false;
	});

	gantt.init("gantt_here");
	gantt.load(webroot + "timeline/gantt_data_original");
</script>

The code for data

public function gantt_data_original(){                                               
        $this->autoRender = false;

	$connector = new JSONGanttConnector($this->Task, "PHPCake");
	$connector->render_table("tasks", "taskid", "original_startdate,original_duration(duration),taskname, progress,projectid,original_duration");                                     
    }

The result