Solved

creating a custom table for Displaying the Data

Posted on 2013-06-18
4
256 Views
Last Modified: 2013-06-21
Hi, I have the following string and i want to split that string to display data in table format but the way i want to display is not working, Here is the data and here is how it should look like

vendorname- #name#: city-#city#: state-#state#:zip-#zip#:in network-#innetwork#

Open in new window


i want to create the above as the following table:

<table>
<tr>
     <td>vendorname</td><td>#vendorname#</td>
     <td>city</td><td>#city#</td>
     <td>state</td><td>#state#</td>
</tr>
<tr><td>zip</td><td>#zip#</td>
<td>&nbsp;</td><td>&nbsp;</td>
<td>&nbsp;</td><td>&nbsp;</td>
</tr>
</table>

trying to create 6 columns in one TR

Here is try so far

<table align="center" width="100%" border="0" cellpadding="4" cellspacing="6" bordercolor="#CCCCCC;">
  <tr>
    <cfloop index="aPair" list="#Demo_Details#" delimiters=":">
    <cfset Key= listFirst(aPair,"-")>
    <cfif listLen(apair,"-") gt 1>
      <cfset value= listLast(aPair,"-")>
      <cfelse>
      <cfset value = "">
    </cfif>
    <cfoutput>
    <td><strong>#key#</strong></td>
    <td>#value#</td>
    </cfoutput>
    </cfloop>
  </tr>
</table>
0
Comment
  • 2
4 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 250 total points
ID: 39256749
You left out "network", but if this must be dynamic ...

Create a counter variable to track the # of columns displayed. Increment it each time you loop. When it reaches 6, start a new row and reset it.

<table ...>
<tr>
<cfset columns = 0>
<cfloop index="aPair" list="#Demo_Details#" delimiters=":">

    ..  your existing code ....


     <cfset columns = columns + 2>
     <!--- start new row and reset --->
     <cfif columns gte 6>
          </tr></tr>
          <cfset columns = 0>
     </cfif>
</cfloop>
</tr>
</table>
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 39257048
so it will be like this

<table ...>
<tr>
<cfset columns = 0>
<cfloop index="aPair" list="#Demo_Details#" delimiters=":">
    <cfset Key= listFirst(aPair,"-")>
    <cfif listLen(apair,"-") gt 1>
      <cfset value= listLast(aPair,"-")>
      <cfelse>
      <cfset value = "">
    </cfif>
    <cfoutput>
    <td><strong>#key#</strong></td>
    <td>#value#</td>
    </cfoutput>
     <cfset columns = columns + 2>
     <!--- start new row and reset --->
     <cfif columns gte 6>
          </tr></tr>
          <cfset columns = 0>
     </cfif>
</cfloop>
</tr>
</table>

i am ooo now, so will try in morning

Thanks
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39257060
Yeah, that looks right. I'll check back tomorrow.
0
 
LVL 28

Assisted Solution

by:Pravin Asar
Pravin Asar earned 250 total points
ID: 39257705
Here is good example code for you.

<cfset str=ArrayNew(1)/>
<cfset str[1]="vendorname- valuename1: city-valuecity1: state-valuestate1:zip-valuezip1:in network-valueinnetwork1"/>
<cfset str[2]="vendorname- valuename2: city-valuecity2: state-valuestate2:zip-valuezip2:in network-valueinnetwork2"/>
<cfset str[3]="vendorname- valuename3: city-valuecity3: state-valuestate3:zip-valuezip3:in network-valueinnetwork3"/>
<table>
<cfloop index="lx" from="1" to="#arraylen(str)#" >

<cfset strArray=ListToArray(str[lx],":",1)/>
<!--- Create Header Row --->
<cfif lx eq 1>
<tr>
<cfloop index="idx" from="1" to="#arraylen(strArray)#">
<cfoutput><th>#ListGetAt(strArray[idx],1,"-")#</th></cfoutput>
</cfloop>
</tr>
</cfif>
<!--- Create Data Rows --->
<tr>
<cfloop index="idx" from="1" to="#arraylen(strArray)#">
<cfoutput><td>#ListGetAt(strArray[idx],2,"-")#</td></cfoutput>
</cfloop>
</tr>
</cfloop>
</table>
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question