How to create a flexible table of items

Discuss news styles, css code, and other Coranto customizations in here...the possibilities are endless, so have at it!

Moderator: Spunkmeyer

How to create a flexible table of items

Postby Dale Ray » Thu Dec 30, 2004 10:46 am

I have written a description of how I implemented a Coranto profile that builds from multiple categories into a table that allows you to specify the number of columns and the number of items per table cell. For my application the items in each cell are in an unordered list.

You can view the document at:

Coranto Docs Wiki

You can see the result at:

My Sports Links Page

This page isn't meant to be useful to the general public and some of the link titles are not useful unless you already know where they go, but you can get an idea of the output of the style from viewing it. There are 4 column and 2 column versions. The page is a publicly accessible favorites page of sites I access for work.

This arose out of a need I had and I thought I would share it in case someone else needs something similar. The news columns addon didn't quite meet my needs - so I hacked out the solution presented in the doc file. This is essentially a Coranto style that build a table of x number of columns with a maximum of x items per column. A new cell is started for each category or any time the number of items in a category exceeds the maximum set. A new row is started each time the specified number of columns is reached.

Suggestions are welcome for improvement in both the technique and the document.

BTW - I am no code expert and I know that the code I have posted could be improved, but what I posted DOES WORK. I wish more people would not worry about their code being picked apart and post examples of stuff that works. Too often all we see is the code that doesn't work when people are having problems.

To get to the published version I put in about 10 hours of time. I did at least 6 forum searches for info and used my own Item Counter HowTo as a reference (I told you I write the docs for myself :wink: ). If one other person uses this work I have saved them the time I spent. So, if you post your success story it may save another user time in the future!

Edit: 8/4/2006 - Links updated
Last edited by Dale Ray on Fri Aug 04, 2006 3:24 pm, edited 2 times in total.
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby Parahead » Thu Dec 30, 2004 12:50 pm

Nice work Dale! :-D

The only comment I have is that if the TD's is unbalanced between the TR's you will finish of the table without having the same amount of TD's in the last TR as in the rest. Actually the same problem exists in the News Columns 1.0 addon and can be fixed with a little modulus at the end of the table creation process. Below I present a solution I use in my own copy of News Columns which will fix this. The same method could maybe be applied to your solution?
Code: Select all
## Count the total number of news, used by BuildNews_CloseFile to wrap things up
$addon->hook(BuildNews_Filtering,\<<'END_CODE');
 if ($newsprofiles{$i}->{'NewsColumns'}) {
  $newscolumnstotalitems{$i}++;
 }
END_CODE

## Make sure to end the table with the right amount of td´s and finaly finish things off with a tr
$addon->hook(BuildNews_CloseFile,\<<'END_CODE');
 if ($newsprofiles{$key}->{'NewsColumns'}) {
  $anyleftovers = ($newscolumnstotalitems{$key} % $newsprofiles{$key}->{'NewsColumnsNum'});
  if($anyleftovers) {
   for(; $anyleftovers < $newsprofiles{$key}->{'NewsColumnsNum'}; $anyleftovers++) {
     print $value qq~$newsprofiles{$key}->{'NewsColumnsTD'}&nbsp;</td>~;
   }
   print $value qq~</tr>~;
  }
 }
END_CODE
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby Dale Ray » Thu Dec 30, 2004 7:45 pm

Parahead wrote:The only comment I have is that if the TD's is unbalanced between the TR's you will finish of the table without having the same amount of TD's in the last TR as in the rest.


Thanks for pointing that out Parahead. I have implemented a check in the style for this and set it to pad the last row with empty cells, if needed. Document revised, link is the same.
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana


Return to Customization

Who is online

Users browsing this forum: No registered users and 1 guest

cron