-3

I need the html table for the following table structure.

Table

This is something similar I have tried till now: (this is a .cshtml view, which takes a model as input)

    <table>
        <tbody>
            <tr>
                <th>Code Number of Equipment</th>
                <th>Name of Equipment</th>
                <th>Brand</th>
                <th>Model</th>
                <th>Quantity</th>

                <th>Check Item</th>
                <th>Note</th>
                <th>Quoted Price</th>
            </tr>
            @foreach (var equipment in Model.Equipments)
            {
                <tr>
                    <td>@equipment.Code</td>
                    <td>@equipment.Name</td>
                    <td>@equipment.EquipmentBrand</td>
                    <td>@equipment.EquipmentModel</td>
                    <td>@String.Format("{0:n0}", equipment.Quantity)</td>
                    <td colspan="2">
                        <table >
                            <tbody >
                                @foreach (var item in equipment.EligibilityChecksheets)
                                {
                                    <tr>
                                        <td>@item.CheckListItem</td>
                                        <td>@item.Note</td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </td>
                    <td>@String.Format("{0:n0}", Model.Currency + " " + equipment.UnitPrice)</td>
                </tr>
            }
            <tr>
                <th></th>
                <th></th>
                <th></th>
                <th></th>
                <th></th>
                <th>Total : </th>
                <th>@String.Format("{0:n0}", Model.Currency + " " + Model.TotalPrice)</th>
            </tr>
        </tbody>
    </table>

The problem with this code is - there is a gap between <td> and the inner table. I want to do this work using rowspan - is it possible to do it for this scenario?

Muntasir
  • 798
  • 1
  • 14
  • 24
Ismail Hossen
  • 31
  • 1
  • 7
  • 2
    SO not coding service bro ? what you have done? – soorapadman Nov 14 '17 at 08:20
  • Is there any tutorial on HTML charts that Mister Google is not able to provide ? In any case you better read [How To Ask](https://stackoverflow.com/help/how-to-ask) – F0XS Nov 14 '17 at 08:25
  • Try here http://tableizer.journalistopia.com/ (if you have this table in word or excel file) and please avoid asking this sort of questions here. – Sankar Nov 14 '17 at 08:29
  • related: [Html table tr inside td](https://stackoverflow.com/questions/17088868/html-table-tr-inside-td) – Muntasir Nov 14 '17 at 12:14

1 Answers1

1

When you are making an HTML table, the table rows of the table are constructed sequentially in HTML; i.e.- once you create a new <tr>, you can't add new <td> or other table elements in any previous <tr> directly from HTML.

For this reason, any variant of this approach will not work as you are expecting:

<table>
    foreach(parent-row in parent-table)
    {
        <tr>
            <!-- parent table data of each row in "td"s with rowspan -->
            foreach(child-row in child-table)
            {
                <tr>
                    <!-- child table data of each row in "td"s without rowspan -->
                </tr>
            }
            <!-- remaining parent table data of each row in "td"s with rowspan -->
        </tr>
    }
</table>

One thing I can think of about how you can do what you are asking for is - completely construct the first row - including the first row of the child table. After constructing that row, you can construct the remaining rows of the child table for that particular parent table row.

In code, the approach will be something like this (considering rowspan = 'number of rows in child table for a particular row in the parent table'):

<table>
    foreach(parent-row in parent-table)
    {
        <tr>
            <!-- parent table data of each row in "td"s with rowspan -->
            foreach(child-row in child-table) // this loop will iterate only once
            {
                <!-- child table data of first row in "td"s without rowspan -->
            }
            <!-- remaining parent table data of each row in "td"s with rowspan -->
        </tr>
        <!-- parent table row with first row of child table for that parent table row created -->
        <!-- creating the remaining rows of the child table -->
        foreach(child-row in child-table) // this loop will iterate (rowspan - 1) times
        {
            <tr>
                <!-- child table data of each row except first row in "td"s without rowspan -->
            </tr>
        }
    } // parent table row with its corresponding child table fully constructed
</table>
Muntasir
  • 798
  • 1
  • 14
  • 24