I'm still unable to make treetable as my expectation. My data is from mysql database with 8 level of hierarchy and thousands of records.
I followed the answer posted by bcoughlan to question : How to create a collapsing tree table in html/css/js? and use data from my database.
It works very well, but :
It tooks very long time to load the table in the beginning, as my AJAX still loop all data from database in the beginning (I don't have knowledge about this, only copy and trial).
I can make the tree colapsed at the first time by using style="display: none;" but when I click any node from that 1st level, it expands all levels below that node (2nd until 8th level) instead of expanding the 2nd level only.
I still cannot figure out how to make AJAX script for the above 2 concerns, to make the page loading time shorter in the beginning of the page.
UPDATE PROGRESS :
Now I can make the AJAX works for the 2nd level.
Still trying although dont have idea how to make it to the 3rd level until 8th level. :)
My script now is as followed, while trying to the 3rd level:
Main.php
<html> <head> <style type="text/css"> .name { color: #000000; } .folderclose { height: 16px; width: 16px; display: inline-block; } .area .last { background-image: url(02_files/01_images/paper_small.png); } .folderclose { background-image: url(02_files/01_images/folder_green.png); } .expand .tog { background-image: url(02_files/01_images/folder_green_open.png); } </style> <script type="text/javascript" src="jquery-2.1.4.js"></script> </head> <body> <form> <table> <tr><th>No</th> <th>Area & Plant</th> <th>Location</th> <th>Main Group</th> <th>Sub Group</th> <th>Function Group</th> <th>Functional Location</th> <th>Equipment</th> </tr> <? mysql_connect("localhost","root",""); mysql_select_db("sfer"); $areaid = 1; $sql = mysql_query("SELECT DISTINCT(Business_Area) FROM b01_functional_location"); while($data=mysql_fetch_array($sql)){?> <tr id="area"> <td align='center' class="id"><?=$areaid?></td> <td align='left' width='400'> <a class="folderclose"></a> <a title='<?=$areaid.'. '.$data['Business_Area']?>' href="javascript:void(0)" class="name"><?=$data['Business_Area']?></a></td></tr> <tr id="plant<?=$areaid?>"></tr><? $areaid++; } if (!empty($_POST['area'])){ $plantid = 1; $sql = mysql_query("SELECT DISTINCT(Plant) FROM b01_functional_location WHERE Business_Area='$_POST[area]'"); while($data=mysql_fetch_array($sql)){?> <tr id="plant"> <td align='center' class="id"><?=$plantid?></td> <td align='left' width='400'> <a class="folderclose"></a> <a title='<?=$plantid.'. '.$data['Plant']?>' href="javascript:void(0)" class="name"><?=$data['Plant']?></a></td></tr> <tr id="location<?=$plantid?>"></tr><? $plantid++; }}?> </table> </form> </body> <script type="text/javascript"> $('document').ready(function(){ $('#area .name').click(function() { var area = $(this).text(); var areaid = $(this).parent().parent().find('.id').text(); $('#plant'+areaid).html('<img src="02_files/01_images/loading.gif">'); $.ajax({ type: 'POST', url: 'Action.php', data: 'area='+area+'&areaid='+areaid, success: function(data){ $('#plant'+areaid).html(data).toggle(); } }); }); $('#plant .name').click(function() { var plant = $(this).text(); var plantid = $(this).parent().parent().find('.id').text(); $('#location'+plantid).html('<img src="02_files/01_images/loading.gif">'); $.ajax({ type: 'POST', url: 'Action.php', data: 'plant='+plant+'&plantid='+plantid, success: function(data){ $('#location'+plantid).html(data); } }); }); }); </script>
Action.php
<?php mysql_connect("localhost","root",""); mysql_select_db("sfer"); if (!empty($_POST['area'])){ $plantid = 1; $sql = mysql_query("select DISTINCT(Plant), Plant_Description from b01_functional_location where Business_Area='$_POST[area]'"); while($data=mysql_fetch_array($sql)){?> <tr id="plant"> <td align='center' class="id"><?=$plantid?></td> <td align='left' width='400'> <a class="folderclose"></a> <a title='<?=$plantid.'. '.$data['Plant']?>' href="javascript:void(0)" class="name"><?=$data['Plant']?></a></td> <td align='left'><?=$data['Plant_Description']?></td> </tr><? $plantid++;} } if (!empty($_POST['plant'])){ $locationid = 1; $sql = mysql_query("select DISTINCT(Location), Location_Desc from b01_functional_location where Plant='$_POST[plant]'"); while($data=mysql_fetch_array($sql)){?> <tr id='location'> <td align='center' class="id"><?=$locationid?></td> <td align='left' width='400'> <a class="folderclose"></a> <a title='<?=$locationid.'. '.$data['Location']?>' href="javascript:void(0)" class="name"><?=$data['Location']?></td> <td align='left'><?=$data['Location_Desc']?></td> </tr><? $locationid++;} }
Need your help.