Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recursive category collapse / expand

Status
Not open for further replies.

imstillatwork

IS-IT--Management
Sep 26, 2001
1,605
US
I'm having a heck of a time figuring out how to collaps and expand this category tree correctly based on the url variable 'path'

Any ideas would be awsome. It looks so simple at first. maybe I am trying too hard?

I'm aiming for unlimited category levels for a store catalog I'm working on to replace my old standard code of 2 levels only that I built several years ago.

In action:

I've tried several things to get it to collapse and expand properly, but left it unmolested for you guys to play with. Please!!


Code:

Code:
<!--- default values for vars --->
<cfparam name="attributes.parentid" default="0">
<cfparam name="attributes.path" default="0">

<!--- query to get categories --->
<cfquery datasource="#application.dsn#" name="qgetcats">
	SELECT * FROM cart_categories
	WHERE categories_parent_id = #attributes.parentid#
	ORDER BY categories_name ASC
</cfquery>

<!--- output query --->
<cfoutput query="qgetcats">
	<!--- set path for url --->
	<cfif attributes.path EQ 0>
		<!--- if no path is set, make one with the current categories_id --->
		<cfset path=categories_id>
	<cfelse>
		<!--- if path is set, add to it with the current categories_id --->
		<cfset path=listappend(attributes.path,categories_id,"_")>
	</cfif>

	<!--- indentation level --->
	<cfset padding=listlen(path,"_")*10>
	<!--- bold if current pick --->
	<cfif url.path EQ path>
		<cfset weight="bold">
	<cfelse>
		<cfset weight="normal">
	</cfif>
	<!--- display category in div --->
	<div style="padding-left:#padding#px;font-weight:#weight#;">
	<a href="index.cfm?path=#path#">#categories_name#</a>
	</div>
	<!--- rinse, repeat --->
	<cf_cats parentid="#categories_id#" path="#path#">
</cfoutput>

Basicly all of the childeren of any expanded or current levels need to be visable also.

For example see
 
Basicly all of the childeren of any expanded or current levels need to be visable also."

that might not make sense.....

See the example url of how I would like it to behave.

thanks!!

 
You want to remove the last element of a list? You don't need a loop for that.

<cfset x = listDeleteAt(myList, listLen(mylist, "_"), "_")>

If you don't ask the right questions, you don't get the right answers. A question asked in the right way often points to its own answer. Asking questions is the ABC of diagnosis. Only the inquiring mind solves problems.

-Quote by Edward Hodnett
 
That code blindness for ya. I even checked through the references to see if I was forgeting a function.

That will help get me closer.

Any other ideas on the overall collapsing / expanding would be nice too!



 
okay!

Can someone please check this over and see if it can be improved?? (not visualy, I'll work on that later.)


Code:
<!--- default values for vars --->
<cfparam name="attributes.parentid" default="0">
<cfparam name="attributes.path" default="0">

<!--- query to get categories --->
<cfquery datasource="#application.dsn#" name="qgetcats">
	SELECT * FROM cart_categories
	WHERE categories_parent_id = #attributes.parentid#
	ORDER BY categories_name ASC
</cfquery>

<!--- output query --->
<cfoutput query="qgetcats">
	<!--- set path for url --->
	<cfif attributes.path EQ 0>
		<!--- if no path is set, make one with the current categories_id --->
		<cfset path=categories_id>
	<cfelse>
		<!--- if path is set, add to it with the current categories_id --->
		<cfset path=listappend(attributes.path,categories_id,"_")>
	</cfif>

	<!--- indentation level --->
	<cfset padding=listlen(path,"_")*10>
	<!--- bold if current pick --->
	<cfif url.path EQ path>
		<cfset weight="bold">
	<cfelse>
		<cfset weight="normal">
	</cfif>
	
	<!--- switch to show category or not --->
	<cfset show=0>
	<!--- all 1st level categories are shown --->
	<cfif attributes.path EQ 0>
		<cfset show=1>
	</cfif>
	<!--- check that attributes.path is in url.path for expanding category paths --->
	<cfif attributes.path EQ left(url.path,len(attributes.path))>
		<cfset show=1>
	</cfif>

	<!--- display category in div --->
	<cfif show>
	<div style="padding-left:#padding#px;font-weight:#weight#;">
		<a href="index.cfm?path=#path#">#categories_name#</a>
	</div>
	</cfif>
	<!--- rinse, repeat --->
	<cf_cats parentid="#categories_id#" path="#path#">
</cfoutput>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top