How to loop through array and output in multiple columns? - coldfusion

I need help looping through my data and outputting it into multiple columns. Currently, it displays vertically right under the next set of data in the array. Please help.
<cfloop array="#UserAddresses#" index="UA">
<tr>
<td>City: </td>
<td><cfif NOT Len(#UA.city.xmlText#)>N/A<cfelse><cfoutput>#UA.city.xmlText#</cfoutput></cfif></td>
</tr>
<tr>
<td>State: </td>
<td><cfif NOT Len(#UA.state.xmlText#)>N/A<cfelse><cfoutput>#UA.state.xmlText#</cfoutput></cfif></td>
</tr>
<tr>
<td>Zip Code: </td>
<td><cfif NOT Len(#UA.zipcode.xmlText#)>N/A<cfelse><cfoutput>#UA.zipcode.xmlText#</cfoutput></cfif></td>
</tr>
</cfloop>
</cfif>

You want the City, State and Zip Code to be headers? Then this would work
<cfoutput>
<tr>
<td>City: </td>
<td>State: </td>
<td>Zip Code: </td>
</tr>
<cfloop array="#UserAddresses#" index="UA">
<tr>
<td><cfif NOT Len(UA.city.xmlText)>N/A<cfelse>#UA.city.xmlText#</cfif></td>
<td><cfif NOT Len(UA.state.xmlText)>N/A<cfelse>#UA.state.xmlText#<</cfif></td>
<td><cfif NOT Len(UA.zipcode.xmlText)>N/A<cfelse>#UA.zipcode.xmlText#</cfif></td>
</tr>
</cfloop>
</cfoutput>
It works because <tr></tr> defines a table row and <td></td> defines a cell in that row. In your case, you were doing multiple rows without cells, thus you were getting your content in a column, instead of a row. A side note is that <cfoutput></cfoutput> should be used only once per page and not around every variable.

Related

Openoffice Calc VLOOKUP with multiple sheets

I am working with this data in Apache OpenOffice 4.1.2 with the goal of a vlookup that allows for cross sheet lookup of data in Sheet1 being added to Sheet2 base on the column pn. Here is the equation I have now but its not lining up right now. Any suggestions/corrections welcome.
In Sheet 2 using this.
=VLOOKUP(A2; Sheet1.A2:Sheet1.C500; 2; 1)
From What I understand Im expecting the code to return the information in the name column from Sheet1 based on the match of the pn column across all 500 rows.
Sheet1<br>
<table>
<thead>
<tr>
|<th>code</th>|
|<th>name</th>|
|<th>pn</th>|
</tr>
</thead>
<br>
<tbody>
<tr>
|<td>111</td>|
|<td>one</td>|
|<td>101</td>|
</tr>
<br>
<tr>
|<td>112</td>|
|<td>two</td>|
|<td>102</td>|
</tr>
</table>
<br>
Sheet2<br>
<table>
<thead>
<tr>
|<th>pn</th>|
|<th>qty</th>|
|<th>cur</th>|
</tr>
</thead>
<br>
<tbody>
<tr>
|<td>102</td>|
|<td>200</td>|
|<td> $ </td>|
</tr>
<br>
<tr>
|<td>101</td>|
|<td>150</td>|
|<td> $ </td>|
</tr>
</table>

How to output a message when query result is [empty string] in ColdFusion?

I have a query written in a stored procedure and the data is dumping just fine. Some of the results return [empty string] and in those cases, I'm trying to output a different message. Here's what I have thus far:
Looping through the query:
<cfloop query="#inactiveAdmins#">
<tr>
<td class="text-left">#Admin_Name#</td>
<td class="text-left">#Dept_Name#</td>
<td class="text-left">#Acad_Lead#</td>
<td class="text-left">#Acad_Lead_Email#</td>
<td class="text-right">#dateFormat(Last_Logon, 'mmm dd, yyyy')#</td>
</tr>
</cfloop>
At the top of the page, I'm running this cfif statement.
<cfif #inactiveAdmins.Last_Logon# eq "">
Never Logged On
<cfelse>
#inactiveAdmins.Last_Logon#
</cfif>
But, in my output, I'm still getting a display with no message.
When I try to run the condition inside the loop, I get the following:
Is this supposed to be inside your table? Make sure you wrap it inside a tr and td.
<cfloop query="#inactiveAdmins#">
<tr>
<td class="text-left">#Admin_Name#</td>
<td class="text-left">#Dept_Name#</td>
<td class="text-left">#Acad_Lead#</td>
<td class="text-left">#Acad_Lead_Email#</td>
<td class="text-right">#(Len(Last_Logon) ? dateFormat(Last_Logon, 'mmm dd, yyyy') : 'Never Logged On')#</td>
</tr>
</cfloop>
Or the long form:
<cfloop query="#inactiveAdmins#">
<tr>
<td class="text-left">#Admin_Name#</td>
<td class="text-left">#Dept_Name#</td>
<td class="text-left">#Acad_Lead#</td>
<td class="text-left">#Acad_Lead_Email#</td>
<td class="text-right">
<cfif Len(Last_Logon)>
#dateFormat(Last_Logon, 'mmm dd, yyyy')#
<cfelse>
Never Logged On
</cfif>
</td>
</tr>
</cfloop>

checking the existence while printing value in a table

I am displaying results in a table after looping through a query. For TestNumber, there are some results in my query where the number is not present and
hence I want to display N/A instead of just blank in the table. So, I am checking the existence
using IsDefined, but for some reason it keeps on printing N/A everytime.
<cfloop query="GetMyList1">
<tr>
<td align="center">#TestName#</td>
<cfif IsDefined(TestNumber) >
<td align="center">#TestNumber#</td>
<cfelse>
<td align="center">N/A</td>
</cfif>
<td align="center">#Date#</td>
</tr>
</cfloop>
You would want to check if there is a length of the item. The field exists, so isDefined will always return true
<cfloop query="GetMyList1">
<tr>
<td align="center">#GetMyList1.TestName#</td>
<td align="center"><cfif len(trim(GetMyList1.TestNumber))>#GetMyList1.TestNumber#<cfelse>N/A</cfif></td>
<td align="center">#GetMyList1.Date#</td>
</tr>
</cfloop>

Validating html-style table data with XSLT

I need to be able to check xml with html-style table data to ensure that it's "rectangular". For example this is rectangular (2x2)
<table>
<tr>
<td>Foo</td>
<td>Bar</td>
</tr>
<tr>
<td>Baz</td>
<td>Qux</td>
</tr>
</table>
This is not
<table>
<tr>
<td>Foo</td>
<td>Bar</td>
</tr>
<tr>
<td>Baz</td>
</tr>
</table>
This is complicated by row and column spans and the fact that I need to accept two styles of markup, either where spanned cells are included as empty td or where span cells are omitted.
<!-- good (3x2), spanned cells included -->
<table>
<tr>
<td colspan="2">Foo</td>
<td/>
<td rowspan="2">Bar</td>
</tr>
<tr>
<td>Baz</td>
<td>Qux</td>
<td/>
</tr>
</table>
<!-- also good (3x2), spanned cells omitted -->
<table>
<tr>
<td colspan="2">Foo</td>
<td rowspan="2">Bar</td>
</tr>
<tr>
<td>Baz</td>
<td>Qux</td>
</tr>
</table>
Here are a bunch of examples of bad tables where it's ambiguous how to deal with them
<!-- bad, looks like spanned cells are included but more cells in row 1 than 2 -->
<table>
<tr>
<td colspan="2">Foo</td>
<td/>
<td rowspan="2">Bar</td>
<td>BAD</td>
</tr>
<tr>
<td>Baz</td>
<td>Qux</td>
<td/>
</tr>
</table>
<!-- bad, looks like spanned cells are omitted but more cells in row 1 than 2 -->
<table>
<tr>
<td colspan="2">Foo</td>
<td rowspan="2">Bar</td>
<td>BAD</td>
</tr>
<tr>
<td>Baz</td>
<td>Qux</td>
</tr>
</table>
<!-- bad, can't tell if spanned cells are included or omitted -->
<table>
<tr>
<td colspan="2">Foo</td>
<td rowspan="2">Bar</td>
</tr>
<tr>
<td>Baz</td>
<td>Qux</td>
<td/>
</tr>
</table>
<!-- bad, looks like spanned cells are omitted but a non-emtpy cell is overspanned -->
<table>
<tr>
<td colspan="2">Foo</td>
<td rowspan="2">Bar</td>
</tr>
<tr>
<td>Baz</td>
<td>Qux</td>
<td>BAD</td>
</tr>
</table>
I already have a working XSLT 2.0 solution for this problem that involves normalizing the data to the "spanned cells included" style then validating, however, my solution is cumbersome and starts to perform poorly for tables with an area of greater than 1000 cells. My normalization and validation routines involve iterating sequentially over the cells and passing along a param of cells that should be created by spans and inserting them when I pass their coordinates in the table. I'm not happy with either of them.
I'm looking for suggestions about cleverer ways in which to achieve this validation that hopefully would have better performance profiles on large tables. I need to account for th and td but omitted th from the examples for sake of simplicity, they can be included or ignored in any answers. I'm not checking to see if thead, tbody, and/or tfoot have the same width, this can also be included or omitted. I'm currently using XSLT 2.0 but I'd be interested in 3.0 solutions if they were significantly better than a solution implemented in 2.0.
I don't think this kind of problem is suited for XSLT - especially if you have to process very large tables.
I'd suggest to develop a solution using a procedural languge - maybe using XSLT to pre- or post- process the XML.

JQuery - Problem with selectors (siblings, parents...)

I got a coldfusion query where the result is grouped on country names. With a click on this one, I try to open or close the list under the country. But i cannot work correctly with this siblings and this parents. The result is, if i click on a country name, the fourth one, for example, it close all childrens, and the three country name which are before too.
Can someone help me to choose the right selectors ?
Thank you in advance ,
Michel
The code:
<script type="text/javascript" language="javascript">
$(document).ready(function(){
var toggleMinus = '<cfoutput>#variables.strWebAddress#</cfoutput>/images/bullet_toggle_minus.png';
var togglePlus = '<cfoutput>#variables.strWebAddress#</cfoutput>/images/bullet_toggle_plus.png';
var $subHead = $('table#categorylist tbody th:first-child');
$subHead.prepend('<img src="' +toggleMinus+ '" alt="collapse this section" /> ');
$('img', $subHead).addClass('clickable').click(function(){
var toggleSrc = $(this).attr('src');
if(toggleSrc == toggleMinus){
$(this).attr('src',togglePlus).parents('.country').siblings().fadeOut('fast');
}else{
$(this).attr('src',toggleMinus).parents('.country').siblings().fadeIn('fast');
}
});
});
</script>
<table width="95%" border="0" cellspacing="2" cellpadding="2" align="center id="categorylist">
<thead>
<tr>
<th class="text3" width="15%">
<cfmodule template="../custom_tags/get_message.cfm" keyName="L_ACTOR_CODENUMBER">
</th>
<th class="text3" width="15%">
<cfmodule template="../custom_tags/get_message.cfm" keyName="L_ACTOR_CODE">
</th>
<th class="text3" width="55%">
<cfmodule template="../custom_tags/get_message.cfm" keyName="L_ACTOR_NAME">
</th>
<th class="text3" width="15%">
<cfmodule template="../custom_tags/get_message.cfm" keyName="L_ACTIVE">
</th>
</tr>
</thead>
<tbody id="content">
<cfoutput query="qryCategoryUrl" group="country_name" groupcasesensitive="false">
<tr class="country">
<th style="font-weight:bold; text-align:left;" colspan="4">#country_name#</th>
</tr>
<cfoutput>
<tr>
<td valign="top" class="text3">#Replace(ACTOR_CODENUMBER, Chr(13) & Chr(10), "<br>", "ALL")# </td>
<td valign="top" class="text3">#Replace(ACTOR_CODE, Chr(13) & Chr(10), "<br>", "ALL")# </td>
<td valign="top" class="text3">#Replace(ACTOR_NAME, Chr(13) & Chr(10), "<br>", "ALL")# </td>
<td valign="top" class="text3"><cfmodule template="../custom_tags//get_message.cfm" keyName="#ACTIVE_display(qryCategoryUrl.ACTIVE)#"></td>
</tr>
</cfoutput>
</cfoutput>
</tbody>
</table>
Instead of:
.parents('.country').siblings().fadeOut('fast');
Try this:
.closest('.country').nextUntil('.country').fadeOut('fast');
And of course, apply the same change to the .fadeIn(). You might also look into .fadeToggle()docs.
Here's a (reduced) example: http://jsfiddle.net/redler/5sqJz/. While it doesn't affect the example, presumably you would be setting the initial state of those detail rows as hidden.
woah all that cfmodule usage, cfmodule can be a memory hog.
Although what I always recommend is that people try their pages in whatever browser, and use the SelectorGadget bookmarklet at http://www.selectorgadget.com/
This makes it easier to test and check the correct selector, for your app needs.