Hello,
I'm having a problem finding a way to handle the display of a complex table when some cells have no data.
I have a query that returns a variable number of advertising records for each Content ID value. I am displaying the data inside a table that uses the group attribute for cfoutput to produce a single row for each Content ID value. For example, the first Content ID has 3 items in cells 1 and 2 and then 2 items in cell three. This is fine until there are no items at all in a particular cell. Then the cell is empty and the cell doesn't display. The table looks broken and I haven't found a way to stick a non-breaking space inside the cell to fix the problem.
The problem is similar to what would happen if you were outputing query data in multiple columns and the total number of rows wasn't evenly divisble by the number of columns. If I have 14 records in 3 columns, the last row will only have 2 cells instead of 3 and that last cell doesn't get created unless you write code to accommodate that. I'm not sure this can be done on a row by row basis when I'm grouping data.
Here is the code to produce the current results:
<cfoutput query="getContentAds" group="Menu1ID">
<table border="1" cellspacing="0" cellpadding="2" align="left">
<tr>
<th colspan="8" align="left">#UCase(Level1Name)#</th>
</tr>
<tr>
<th align="center">Item ID</th>
<th align="center">Menu 1</th>
<th align="center">Menu 2</th>
<th align="center">Menu 3</th>
<th align="center">Title</th>
<th align="center">Top 1</th>
<th align="center">Top 2</th>
<th align="center">Top 3</th>
</tr>
<cfoutput group="contentID">
<tr>
<td align="center" valign="top">#ContentID#</td>
<td align="center" valign="top">#Level1Name#</td>
<td align="center" valign="top"><cfif #Level2Name# IS NOT "">
#Level2Name#<cfelse>NA</cfif></td>
<td align="center" valign="top"><cfif #Level3Name# IS NOT "">#Level3Name#<cfelse>NA</cfif></td>
<td align="center" valign="top">#Title#</td>
<cfoutput group="Position_Order">
<td align="center" valign="top"><cfoutput group="AdBankID">
<cfset adList = "">
<cfoutput>
<!--- first determine whether there are any items in the list for this table cell --->
<cfif NOT #ListContains(adList, getContentAds.AdID[currentrow])#>
<cfset adList = #ListAppend(adList, getContentAds.AdID[currentrow])#>
</cfif>
</cfoutput>
#adList#</td>
</cfoutput>
<!--- once the position order changes, we move to a new cell --->
</cfoutput>
</tr>
<!--- when the content ID changes we move to a new row --->
</cfoutput>
</table>
<!--- when the menu category changes we move to a new table --->
</cfoutput>
The resulting table with data looks like this:
<table cellpadding="2" cellspacing="0" border="1">
<tr>
<th colspan="8" align="left">NEWS</th></tr>
<tr>
<th align="center">Item ID</th>
<th align="center">Menu 1</th>
<th align="center">Menu 2</th>
<th align="center">Menu 3</th>
<th align="center">Title</th>
<th align="center">Top 1</th>
<th align="center">Top 2</th>
<th align="center">Top 3</th>
</tr>
<tr>
<td align="center">355</td>
<td align="center">News</td>
<td align="center">NA</td>
<td align="center">NA</td>
<td align="center">First Test</td>
<td align="center">10, 12, 13</td>
<td align="center">14, 15, 16</td>
<td align="center">6, 9</td>
</tr>
<tr>
<td align="center">384</td>
<td align="center">News</td>
<td align="center">Sports</td>
<td align="center">Basketball</td>
<td align="center">Second Test</td>
<td align="center">10</td>
<td align="center">10</td>
<td align="center">6, 9</td>
</tr>
</table>
This is fine except that it assumes there is data for all cells in each row. I need to be able to create all table cells on each row even when one or more of them have no content. When a table cell is empty, the grouping process moves to the next cell or next row and leaves the table incomplete or unbalanced.
Maybe there is no practical way to handle this and I should try another approach, but I didn't want to give up before checking to see if anybody else had an idea.
I'm having a problem finding a way to handle the display of a complex table when some cells have no data.
I have a query that returns a variable number of advertising records for each Content ID value. I am displaying the data inside a table that uses the group attribute for cfoutput to produce a single row for each Content ID value. For example, the first Content ID has 3 items in cells 1 and 2 and then 2 items in cell three. This is fine until there are no items at all in a particular cell. Then the cell is empty and the cell doesn't display. The table looks broken and I haven't found a way to stick a non-breaking space inside the cell to fix the problem.
The problem is similar to what would happen if you were outputing query data in multiple columns and the total number of rows wasn't evenly divisble by the number of columns. If I have 14 records in 3 columns, the last row will only have 2 cells instead of 3 and that last cell doesn't get created unless you write code to accommodate that. I'm not sure this can be done on a row by row basis when I'm grouping data.
Here is the code to produce the current results:
<cfoutput query="getContentAds" group="Menu1ID">
<table border="1" cellspacing="0" cellpadding="2" align="left">
<tr>
<th colspan="8" align="left">#UCase(Level1Name)#</th>
</tr>
<tr>
<th align="center">Item ID</th>
<th align="center">Menu 1</th>
<th align="center">Menu 2</th>
<th align="center">Menu 3</th>
<th align="center">Title</th>
<th align="center">Top 1</th>
<th align="center">Top 2</th>
<th align="center">Top 3</th>
</tr>
<cfoutput group="contentID">
<tr>
<td align="center" valign="top">#ContentID#</td>
<td align="center" valign="top">#Level1Name#</td>
<td align="center" valign="top"><cfif #Level2Name# IS NOT "">
#Level2Name#<cfelse>NA</cfif></td>
<td align="center" valign="top"><cfif #Level3Name# IS NOT "">#Level3Name#<cfelse>NA</cfif></td>
<td align="center" valign="top">#Title#</td>
<cfoutput group="Position_Order">
<td align="center" valign="top"><cfoutput group="AdBankID">
<cfset adList = "">
<cfoutput>
<!--- first determine whether there are any items in the list for this table cell --->
<cfif NOT #ListContains(adList, getContentAds.AdID[currentrow])#>
<cfset adList = #ListAppend(adList, getContentAds.AdID[currentrow])#>
</cfif>
</cfoutput>
#adList#</td>
</cfoutput>
<!--- once the position order changes, we move to a new cell --->
</cfoutput>
</tr>
<!--- when the content ID changes we move to a new row --->
</cfoutput>
</table>
<!--- when the menu category changes we move to a new table --->
</cfoutput>
The resulting table with data looks like this:
<table cellpadding="2" cellspacing="0" border="1">
<tr>
<th colspan="8" align="left">NEWS</th></tr>
<tr>
<th align="center">Item ID</th>
<th align="center">Menu 1</th>
<th align="center">Menu 2</th>
<th align="center">Menu 3</th>
<th align="center">Title</th>
<th align="center">Top 1</th>
<th align="center">Top 2</th>
<th align="center">Top 3</th>
</tr>
<tr>
<td align="center">355</td>
<td align="center">News</td>
<td align="center">NA</td>
<td align="center">NA</td>
<td align="center">First Test</td>
<td align="center">10, 12, 13</td>
<td align="center">14, 15, 16</td>
<td align="center">6, 9</td>
</tr>
<tr>
<td align="center">384</td>
<td align="center">News</td>
<td align="center">Sports</td>
<td align="center">Basketball</td>
<td align="center">Second Test</td>
<td align="center">10</td>
<td align="center">10</td>
<td align="center">6, 9</td>
</tr>
</table>
This is fine except that it assumes there is data for all cells in each row. I need to be able to create all table cells on each row even when one or more of them have no content. When a table cell is empty, the grouping process moves to the next cell or next row and leaves the table incomplete or unbalanced.
Maybe there is no practical way to handle this and I should try another approach, but I didn't want to give up before checking to see if anybody else had an idea.