Timeline tree view load options from DB

I am trying to load the sections of a timeline view in tree mode from a database, but it doesn’t appear to be working. Here is a snippet:

    $p_sql = "SELECT p.id as value, p.title as label, parent FROM product p";
    $pi_sql = "SELECT pi.* FROM product_item pi ";
    
    $calendar = new SchedulerConnector($res);
    $list = new OptionsConnector($res);
    $list->render_sql($p_sql,"product_id","id(value),title(label)","","parent");
    $calendar->set_options("product", $list);
    $calendar->render_sql($pi_sql,"id","start,end,title,product_id,monetization_level","product_id");

In testing, I have one “child” item in the product table with the “parent” field set correctly. But when I display the view, the child item shows up as its own top-level element, not under the parent.

Any ideas?

			var sections = scheduler.serverList("product");

			scheduler.createTimelineView({
				name:	"timeline",
				x_unit:	"month",
				x_date:	"%M",
				x_step:	1,
				x_size: 14,
				y_property:	"product_id",
				y_unit: sections,
				render:"tree",
				folder_events_available: true,
				section_autoheight: true,
				fit_events: true
			});

Hello,

Connectors won’t help you generate xml/json for tree timeline view. You will need to to form options object yourself on client-side.

Kind regards,
Ilya

Hi, I am also trying to load sections from a table, a users table to be precise. How would I be able to do this. I noticed someone mentioned client side ? Any details on how I would do this thanks!

Has anyone done it?

Hello,
TreeTimeline can load sections as a tree structure, i.e
1)[ {key:1, label:"root", children:[ {key:2, label:"child"}, {key:3, label:"child 2"}, .. ], {key:4, label:"second node", ...} ]

When, you retreive data from the database, most probably you deal with plain structure like following:
2)[ {id:1, text:"root", parent_id:0}, {id:2, text:"child", parent_id:1}, {id:3, text:"child 2", parent_id:1},
So you need to iterate array of elements b[/b] and build a tree b[/b] that can be consumed by TreeTimeline. It can be done either on server or on client.

Thx for the tip. If someone is interested I done it on the server side, like this:

$parent_items = $this->parent_model->get_items_by_id($array_ids); $seccions_tree = array(); for ($i=0; $i<count($parent_items); $i++) { $seccions_tree[$i] = $parent_items[$i]; $children_items = $this->children_model->get_items_by_parent($parent_items[$i]['key']); foreach ($children_items as $children_item) $parent_items[$i]['children'][] = $children_item; } $this->data['seccions_tree'] = $seccions_tree; $this->load->view('scheduler/scheduler', $this->data);

And on the client side, on the TimelineView creation I define the y_unit parameter like this:

y_unit:<?php echo json_encode($seccions_tree); ?>,

I don’t think that’s the cleanest and fastest way (I’d like to use the OptionsConnector and $conn->set_options of the connector), but it works. Any advice is welcome!