简体   繁体   中英

How to Group columns in front end?

Table has to be displayed in front end. Following is the code.

<logic:present name="searchStudent">
    <table class=" tblSearchResult" border="1" cellspacing="0" cellpadding="0">
    <caption><b><bean:message key="label.student.details.display"/></b></caption>
    <tr>
        <td align="center"><b><bean:message key="label.student.class.code"/></b></td>
        <td align="center"><b><bean:message key="label.student.name.code"/></b></td>
        <td align="center"><b><bean:message key="label.student.section.code"/></b></td>
        <td align="center"><b><bean:message key="label.edit" /></b></td>
        <td align="center"><b><bean:message key="label.delete" /></b></td>
    </tr>
    <logic:iterate name="searchStudent" id="row">
    <tr>
        <td rowspan="2">
            <bean:write name="row" property="sclass" />
        </td>
        <td>
            <bean:write name="row" property="sname" />
        </td>
        <td>
            <bean:write name="row" property="section" />
        </td>
            
        <td rowspan="2" style="text-align:center;"><input
                onclick="clearMessage();updateStudent(this);"
                type="image"
                src="${pageContext.request.contextPath}/images/pen_edit_thick.png"
                class="imgEditPen"
                title="<bean:message key="button.tooltip.edit"/>"></td>
            <td rowspan="2" style="text-align:center;"><input
                onclick="clearMessage();deleteStudent();"
                type="image"
                src="${pageContext.request.contextPath}/images/icon_delete.gif"
                class="imgEditPen"
                title="<bean:message key="button.tooltip.remove"/>"></td>
        
    </tr>
    </logic:iterate>
    </table>
</logic:present>

It has three columns in table namely class,student name and section. Since class is same for some student it has to spanned across students having same class. Following is the sample output.

在此处输入图像描述

Data is fetched from Backend.

Colspan Attribute can merge columns in a table.

<td colspan="2">Sum: $180</td>

Example

     <table>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
  <tr>
    <td colspan="2">Sum: $180</td>
  </tr>
</table>

Result

在此处输入图像描述

Refer: https://www.w3schools.com/tags/att_td_colspan.asp

Rowspan Attribute:

 <tr>
    <td>January</td>
    <td>$100</td>
    <td rowspan="2">$50</td>
  </tr>

https://www.w3schools.com/tags/att_td_rowspan.asp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM