1

Is it possible to write the first column in a table in HTML and then the next column? If you write it like this:

<table>
      <tr>
        <th>Test1</th>
        <th>Test2</th>
        <th>Test3</th>
      </tr>
      <tr>
        <td>Test4</td>
        <td>Test5</td>
        <td>Test6</td>
      </tr>
      <tr>
        <td>Test7</td>
        <td>Test8</td>
        <td>Test9</td>
      </tr>
    </table>

You just write the first row and then the second row. But I want to write the first column first. Is this possible?

Edit: I have 5 Arrays with different sizes. They all include Strings.

Array1[2]: "Thomas", "Jon"

Array2[3]: "Bob", "Karl", "Jake"

Array3[4]: "Stephan", "Barack", "Steve", "Nicole"

Array3[1]: "Robert"

Array5[4]: "Carla", "Carlos", "Niggel", "Cedric"

The Header of the Tables should include the workdays. At the end I will have a Table with 5 Rows and some columns. To create this table I need to write the first Columne with a Loop for the 1. Array. Then a second Column for the second Array and so on. Right? Do you have another idea how to write this table? I hope you understand my problem.

semaxx
  • 43
  • 9

2 Answers2

0

Render the table by rows and then use javascript to invert the table. Here is a jsfiddle

$("a").click(function () {
$("table").each(function () {
    var $this = $(this);
    var newrows = [];
    $this.find("tr").each(function () {
        var i = 0;
        $(this).find("td,th").each(function () {
            i++;
            if (newrows[i] === undefined) {
                newrows[i] = $("<tr></tr>");
            }
            newrows[i].append($(this));
        });
    });
    $this.find("tr").remove();
    $.each(newrows, function () {
        $this.append(this);
    });
});

return false;
});
Thamilhan
  • 13,040
  • 5
  • 37
  • 59
0

That is not how the HTML standard is. You make your table, then you make a row, and then your columns. There is some additional stuff for headers, bodies, etc. But the standard (and only supported method) is by row and not by column.

NOTE: Anyways if you have any specific reason to do like that then please explain your scenario and we will help you to make this working in a correct approach.

Deepak Biswal
  • 4,280
  • 2
  • 20
  • 37