mickaelr / jquery-timelineMe

A flexible timeline plugin
MIT License
57 stars 18 forks source link

dynamically items? #8

Closed asadghazanfary closed 8 years ago

asadghazanfary commented 8 years ago

how can add dynamically items with json records retrive from database?

mickaelr commented 8 years ago

Hi, For the moment we can't add or refresh items, a workaround could be building the timeline only once json records are retrieved, but I think you won't be able to update it later... (could it work for you?)

It's a very important point so I'll work on that after horizontal mode. Thx!

jcr4e commented 8 years ago

Hi, any feedback on this?

mickaelr commented 8 years ago

Hi @jcr4e, thanks for the follow up, I've been quite absent last weeks... Just added this on the TODO list, will try to work on it this WE!

mickaelr commented 8 years ago

@jcr4e @asadghazanfary just added a first try of dynamic load, if you have some time to check it and give me some feedback (some limitations you faced, issue, ...) don't hesitate. Cheers!

jcr4e commented 8 years ago

This is how I do it:

public function displayTree() { ... your SQL query here.. table must have id and parent_id fields $this->makeTree($nodes, 0, $tree); echo json_encode($tree); } private function makeTree( $rst, $level, &$tree ) { for ( $i=0, $n=count($rst); $i < $n; $i++ ) { if ( $rst[$i]['parent_id'] == $level ) { $branch = array( 'name' => $rst[$i]['step'], 'id' => $rst[$i]['id'], 'step_id' => $rst[$i]['step_id'], 'parent_id' => $rst[$i]['parent_id'], 'children' => array() ); $this->makeTree( $rst, $rst[$i]['id'], $branch['children'] ); $tree[] = $branch; } } }

you can then run displayTree using AJAX and load the result on the tree. check sample code below:

                    $('#treeview').tree({
                        data: result,
                        autoOpen: true,
                        dragAndDrop: true,
                        closedIcon: '+',
                        openedIcon: '&ndash;'
                    });

hope this helps.

mickaelr commented 8 years ago

Ok so normally you should be able to use it that way. Tell me if I missed something ;)