views:

27

answers:

1

Given a table like this:

Col 1  |  Col 2
  1         2
  1         3
  2         4

...and could be any number of 1's, 2's, etc. in Col 1. I want to dynamically output something that would look like this:

<table>
    <tr>
        <td rowspan="2">
            1
        </td>
        <td>
            2
        </td>
    </tr>
    <tr>
        <td>
            3
        </td>
    </tr>
    <tr>
        <td rowspan="1">
            2
        </td>
        <td>
            4
        </td>
    </tr>
</table>

My issue is that, for the above html, I would have to count the number of distinct 1's to find the appropriate rowspan number, then go back and iterate through them for the html output. I was just wondering if there was an easier/quicker way to do something similar where I could just iterate through the records and add something once the next row in Col 1 is different than the last row's Col 1.

I read something that sounded like I could just use rowspan="0" for the first record, and divide the groups up by tbody tags like so:

<table>
    <tbody>
        <tr>
            <td rowspan="0">
                1
            </td>
            <td>
                2
            </td>
        </tr>
        <tr>
            <td>
                3
            </td>
        </tr>
    </tbody>
    <tbody>
        <tr>
            <td rowspan="0">
                2
            </td>
            <td>
                4
            </td>
        </tr>
    </tbody>
</table>

...and the rowspan="0" would just span the tbody section it is contained in. I haven't been able to find much info on this method, and I couldn't get it to work in IE or Firefox. So is there anything along those lines that would speed up my html rendering? Thanks in advance.

A: 

How about trying like this?

<table>
  <tbody>
      <tr>
          <td rowspan="10">
              1
          </td>
          <td>
              2
          </td>
      </tr>
      <tr>
          <td>
              3
          </td>
      </tr>
  </tbody>
  <tbody>
      <tr>
          <td rowspan="10">
              2
          </td>
          <td>
              4
          </td>
      </tr>
  </tbody>
</table>

At least on this table it looked like it worked in IE8 and FF 3.6. I'm assuming that if rowspan="10" works fine on a table with 3 rows that has 2 sections (2 rows first, 1 row second) then rowspan="10000" should work as well.

Edit: oh yea, according to a couple of sites, the rowspan="0" works correctly so far only in Opera.

pkauko
Not quite what I was hoping for, but it seems like that's the closest thing to a solution that exists.
Ocelot20
I know that's not exactly what you were looking for, but that was the best I could come up with after not finding a real solution.
pkauko