Question

I am trying to reload (via ajax) data into a Gantt chart using php and jquery. I can draw a gantt chart with my data on the initial load without any issues. I have a ajax save call to update chart data in which I would like to redraw the gantt chart after a successful save.

I am able to load part of the data, ie the title data on the left, but not the dates, I believe it is not in the right format? I am using this gantt chart plugin from github: https://github.com/thegrubbsian/jquery.ganttView

Below is a sample of the data they are using? Is this json data?

I am not sure? How do I format my output to mirror and use this data.

var ganttData = [
{
    id: 1, name: "Feature 1", series: [
        { name: "Planned", start: new Date(2010,00,01), end: new Date(2010,00,03) },
        { name: "Actual", start: new Date(2010,00,02), end: new Date(2010,00,05), color: "#f0f0f0" }
    ]
}, 
{
    id: 2, name: "Feature 2", series: [
        { name: "Planned", start: new Date(2010,00,05), end: new Date(2010,00,20) },
        { name: "Actual", start: new Date(2010,00,06), end: new Date(2010,00,17), color: "#f0f0f0" },
        { name: "Projected", start: new Date(2010,00,06), end: new Date(2010,00,17), color: "#e0e0e0" }
    ]
}, 

My code looks like this:

[{"id":0,"name":"task number 20","series":[{"name":"Bob","start":"new Date(2012,2,19)","end":"new Date(2012,6,11)"}]},{"id":1,"name":"another new posts","series":[{"name":"Bill","start":"new Date(2012,5,22)","end":"new Date(2012,6,27)"}]},here
Was it helpful?

Solution

It's not legal to "call" functions (including constructors) from a json string. JSON isn't anything you can pass to an eval function : http://www.json.org/

You should do the transformation from string to date in your javascript code.

You can send

[{..."start":"Thu Jul 12 2012 16:20:17 GMT+0200 (CEST)"...}]

and in your js code, just after json parsing, iterate over the objects to do

myobj.start = new Date(myobj.start);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top