Folder View 2 Support Product Page

collapse when loaded

Asked 31 Jan 2010 09:11:23
1
has this question
31 Jan 2010 09:11:23 phil osullivan posted:
hi,
i'm grabbing my data for my folder view from a dynamically created <ul> (php generated)and it works fine.
the only issue i'm having is the tree is completely expanded when the page loads, i'd like to have it collapsed.
thanks.

Replies

Replied 01 Feb 2010 12:36:35
01 Feb 2010 12:36:35 Miroslav Zografski replied:
Hello Phil,

Please, provide a link to the page in question if available.

Regards,
Replied 02 Feb 2010 21:13:00
02 Feb 2010 21:13:00 phil osullivan replied:
Hi Miroslav,
here is a link to the page:
www.pdo-solutions.com/benethan/__test/treemenu2.php
here is my php code to generage the list:

<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" type="text/javascript" src="../ScriptLibrary/jquery-latest.pack.js"></script>
<script language="javascript" type="text/javascript" src="../ScriptLibrary/dmxFolderView.js"></script>
<link rel="stylesheet" type="text/css" href="../Styles/dmxTree/Default/treestyle.css" />
<link rel="stylesheet" type="text/css" href="../Styles/dmxTree/Blue_Folder3_24x24/treestyle.css" />
</head>

<body>
<script language="JavaScript" type="text/javascript">
<!--
dmxListToTree({
  bullets : 'plusminus',
  icons   : true,
  struct  : true,
  slide   : true,
  bgcolor : '#FFFFFF',
  theme   : 'Blue_Folder3_24x24',
  toolbar : false,
  objId   : 'FolderView'
});
//-->
</script>

<?php
//connect to database
$link = mysqli_connect('xxx','xxx','xxx');
mysqli_select_db($link,'xxx');

 // get customer id from session created at log in
 $customerid = $_SESSION['CustomerID'];


//get all rows
$query = mysqli_query($link,'SELECT * FROM tblMenu WHERE customerid ='. $customerid . ' ORDER BY name ASC' );

while ( $row = mysqli_fetch_assoc($query) )
{
   $menu_array[$row['id']] = array('rowid' => $row['id'],'name' => $row['name'],'parent' => $row['parent'],'machineid' => $row['machineid']);
}

//recursive function that prints categories as a nested html unorderd list
function generate_menu($parent)
{
        $has_childs = false;
        //this prevents printing 'ul' if we don't have subcategories for this category
        global $menu_array;
        //use global array variable instead of a local variable to lower stack memory requierment
        foreach($menu_array as $key => $value)
        {
        if ($value['parent'] == $parent) 
        {       
         //if this is the first child print '<ul>'                       
         if ($has_childs === false)
        {
        //don't print '<ul>' multiple times                             
        $has_childs = true;
         echo '<ul class="dmxtree Blue_Folder3_24x24" id="FolderView">';
        }
        echo '<li id="'. $value['rowid'] .'"><a href="javascript:;" onclick="alert('.$value['rowid'].');">' . $value['name'] . '</a>';
		//echo '<li id="phtml_'. $value['rowid'] .'"><a href="#"><ins>&nbsp;</ins>' . $value['name'] . '</a>';
		//echo '<li><a href="URL?mid=' . $value['machineid'] . '/">' . $value['name'] . '</a>';
        generate_menu($key);
       
	   //call function again to generate nested list for subcategories belonging to this category
       echo '</li>';
       }
       }
       if ($has_childs === true) echo '</ul>';
       }
       //generate menu starting with parent categories (that have a 0 parent)
       generate_menu(0);
?>
</body>
</html>


thanks Phil.
Replied 04 Feb 2010 09:25:16
04 Feb 2010 09:25:16 Miroslav Zografski replied:
Hello Phil,

all you need to do is to set class "collapsed" to the parent LI elements. Looking at you code I assume those that are returning true on the if ($has_childs === false) check.
Then when the folder View is loaded they will be collapsed.

Regards,

Reply to this topic