Table with multipe row types

0 views
Skip to first unread message

Zack Moore

unread,
Oct 15, 2008, 5:06:43 PM10/15/08
to chainjs
I'm trying to use chain to produce a table like this
<table>
<tr><td colspan="3">Level 1</td><tr>
<tr><th>Col1</th><th>Col2</th><th>Col3</th></tr>
<tr><td>some data</td><td>A</td><td>B</td></tr>
<tr><td>some data</td><td>A</td><td>B</td></tr>
<tr><td>some data</td><td>A</td><td>B</td></tr>
<tr><td colspan="3">Level 2</td><tr>
<tr><th>Col1</th><th>Col2</th><th>Col3</th></tr>
<tr><td>some data</td><td>A</td><td>B</td></tr>
<tr><td>some data</td><td>A</td><td>B</td></tr>
<tr><td colspan="3">Level 3</td><tr>
<tr><th>Col1</th><th>Col2</th><th>Col3</th></tr>
<tr><td>some data</td><td>A</td><td>B</td></tr>
<tr><td>some data</td><td>A</td><td>B</td></tr>
</table>

I apologize if it is a little crowded.
I have 3 levels of data. Each level begins with 1 row that names the
level followed by a new level that repeats the column headers.
Then the data is displayed.

I can't figure out a way using chain to populate a table with
different types of rows.

-Zack Moore

Rizqi Ahmad

unread,
Oct 16, 2008, 4:24:29 AM10/16/08
to chainjs
It would be rather difficult using table, since chain.js requires one
container for one item (in your case it is 3).
Does it need to be a table?

this is a typical example for a recursive chaining. maybe you can see
this post: http://groups.google.com/group/chainjs/browse_thread/thread/348013bc5aa8b559

Vincent Pérès

unread,
Oct 16, 2008, 5:00:06 AM10/16/08
to chainjs
Hello,

Yes you have to build your own builder.

<table class=".table">
<tr class=".columns"><th class=".column"></th></tr>
</table>

For this part it could be like that :

$('.table').items(json).chain({
builder: function(root){
if(this.item().columns){

this.find('.columns').items(this.item().columns).chain({'.column':
'{$data}'});
}
}
});

Zack Moore

unread,
Oct 16, 2008, 10:40:14 AM10/16/08
to chainjs
It doesn't have to use the Table tag, but it does need to stack up and
look like a table with columns that line up and have the correct
widths, etc.
I could try this with div tags but in the past I haven't been able to
get it to look and behave the same.

I'll take a look at the recursive chaining link and see if it helps.

On Oct 16, 4:24 am, Rizqi Ahmad <raid...@yahoo.de> wrote:
> It would be rather difficult using table, since chain.js requires one
> container for one item (in your case it is 3).
> Does it need to be a table?
>
> this is a typical example for a recursive chaining. maybe you can see
> this post:http://groups.google.com/group/chainjs/browse_thread/thread/348013bc5...
>
> On Oct 15, 11:06 pm, Zack Moore <TZMo...@gmail.com> wrote:
>
>
>
> > I'm trying to use chain to produce a table like this
> > <table>
> > <tr><td colspan="3">Level 1</td><tr>
> > <tr><th>Col1</th><th>Col2</th><th>Col3</th></tr>
> > <tr><td>some data</td><td>A</td><td>B</td></tr>
> > <tr><td>some data</td><td>A</td><td>B</td></tr>
> > <tr><td>some data</td><td>A</td><td>B</td></tr>
> > <tr><td colspan="3">Level 2</td><tr>
> > <tr><th>Col1</th><th>Col2</th><th>Col3</th></tr>
> > <tr><td>some data</td><td>A</td><td>B</td></tr>
> > <tr><td>some data</td><td>A</td><td>B</td></tr>
> > <tr><td colspan="3">Level 3</td><tr>
> > <tr><th>Col1</th><th>Col2</th><th>Col3</th></tr>
> > <tr><td>some data</td><td>A</td><td>B</td></tr>
> > <tr><td>some data</td><td>A</td><td>B</td></tr>
> > </table>
>
> > I apologize if it is a little crowded.
> > I have 3 levels of data. Each level begins with 1 row that names the
> > level followed by a new level that repeats the column headers.
> > Then the data is displayed.
>
> > I can't figure out a way using chain to populate a table with
> > different types of rows.
>
> > -Zack Moore- Hide quoted text -
>
> - Show quoted text -

Zack Moore

unread,
Oct 16, 2008, 10:44:48 AM10/16/08
to chainjs
Thanks, Vincent. I'll give this a try although I'm not totally clear
on what your building function is doing.

I think what you are doing is saying "if item has columns then fill in
the data"

if that is the case then how do I specify which data goes in which
column?

Also is it possible to tell one row to only have 1 <td> with
colspan="2" (or whatever I need the colspan to be).

Rizqi Ahmad

unread,
Oct 16, 2008, 2:18:18 PM10/16/08
to chainjs
Hey Zack,

here is a possible solution: http://friendpaste.com/yeCHhafS

it generates one table for each level though. You may have to fix the
width of the tables
Reply all
Reply to author
Forward
0 new messages