Categories > TinyButStrong general >

Dynamic Tables

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: joshhendo
Date: 2010-06-07
Time: 09:03

Dynamic Tables

Hi Everyone,

Firstly, I am only new to TBS, so I haven't been using it for too long, but I decided I needed some form of templating system for a PHP project I am working on, and TBS seemed to be really good, and so far it has been!

Only one thing I am trying to do (which I imagin I would have problems with for any templating system) is I am trying to make a dynamic table.

What I currently have is two arrays with the row headings and the column headings, which both skip a cell (the very top left one, intentionally) and then display the rows and columns as I would like them to.

skipped | col 0  | col 1  |  col2  |  col 3
   row 0   |--------|--------|--------|------
   row 1   |--------|--------|--------|------
   row 2   |--------|--------|--------|------
   row 3   |--------|--------|--------|------

So something like above. I have managed to get this to display wtihout too much trouble, but I think the way I have managed to get it to display isn't the best way (actually, quite a bad way when looking at it).

Now, what I am having problems with is displaying values inside each individual cell. I have a third array that specifies a string, and it's row and column location.

The problem I am having is each cell may have more than one of these values in it, and I want the template to automatically display them in a list (so with <ul> and <li>). What I *could* do is have the array contain the html code for each cell, but that almost defeats the purpose of having a template system and seems a bit hackish.

What is the best way to do list in cells? Each time I try something it just seems to get overly complex and I can't seem to work it out.

Any help is much appreciated.

Regards,
Josh.
By: TomH
Date: 2010-06-07
Time: 12:47

Re: Dynamic Tables

Two things come to mind
First, as to the layout, maybe a table that is just for the outside wrapper containing the row/col for the labels with the content cells inside an inner table.
Second, build an array of arrays for the content data cells and use the headergrp or parentgrp technigue for the block display.
A useful example under "Groupings" at
http://www.tinybutstrong.com/examples.php
should be a good starting point.
By: Skrol29
Date: 2010-06-07
Time: 14:11

Re: Dynamic Tables

Hi Joshhendo

You need to display the item as a simple text if it is alone in the cell, and as an Html list if they are many items in the cell. I agree it is the purpose of the template engine to perform this design job. In another hand, the design you want requires a simple operation which is in fact a bit complicated for a template system, at least too custom to be done in native.

TBS can do this, but it will cost more process time.
  
It can be more simple if you have the number if item for each cell, or if you have the information that the item is unique directly in the item data. If you have it, you can use an automatic sub-block in the cells.
See http://www.tinybutstrong.com/manual.php#html_block_subauto
The automatic sub-block must then have conditional sections: one if the item is unique, another if ti is numerous.

There is another solution, fast but smart and a bit complicated:
Define a custom "onformat" function for the data to display on the cell. (see http://www.tinybutstrong.com/manual.php#html_field_prm_onformat)
Your "ondata" function will do the check of if the item is alone or not alone. Then it will merge the data itself with a first template snippet, or with a second template snippet. That is done in the PHP side, but the PHP code can retrieve a template snippet which is nested in the main template using method $TBS->GetBlockSource().
So all HTML is in the template, but the algorithm to choose which snippet to use is in the PHP side.

I hope this will help,
Regards,