简体   繁体   English

表格:仅显示表格正文的第一行。 如何隐藏后续的第一行?

[英]Table: Show only the first row of table tbody. How to hide the succeeding 1st rows?

The very 1st row of EVERY tbody is the row header (contains the column Names). EVERY正文的第一行是行标题(包含列名)。 The rest of EVERY tbody succeeding 1st rows are not necessary and wanted to hide them. 第1行之后的每个其余部分都没有必要,而是希望将其隐藏。

Classes used: 使用的类:

toprowHeader = 1st row that holds every column names toprowHeader =包含每个列名称的第一行

recordsRow = holds the other record details recordsRow =保存其他记录详细信息

For now it shows like this: 现在,它显示如下:

--------------------------------------------
| MessageID  |  Sender   | Message         |
--------------------------------------------
|         1  | admin     |my admin message |
--------------------------------------------
| MessageID  |  Sender   | Message         |
--------------------------------------------
|         2  | sender1   |reply to admin   | 

Here is the sample structure I wanted to achieve: 这是我想要实现的示例结构:

--------------------------------------------
| MessageID  |  Sender   | Message         |
--------------------------------------------
|         1  | admin     |my admin message |
|         2  | sender1   |reply to admin   | 

Though I have some options to make it easier but the requirement says that every record should be inside a tbody 尽管我有一些选择可以简化操作,但是要求说每条记录都应该放在一个 躯体内

Here is my Sample Table structure: 这是我的样本表结构:

<table class="gridtable">
    <tbody>
            <tr class="toprowHeader" >
                <td class="">...</td>
            </tr>
            <tr class="recordsRow " >
                <td class="">...</td>
            </tr>
            <tr class="recordsRow " >
                <td class="">...</td>
            </tr>               

    </tbody>
    <tbody>
            <tr class="toprowHeader">
                <td class="">...</td>
            </tr>
            <tr class="recordsRow ">
                <td class="">...</td>
            </tr>
            <tr class="recordsRow ">
                <td class="">...</td>
            </tr>               
    </tbody>    
</table>

Added requirement: 附加要求:

A lot of you questioned the table structure above but the main reason why I placed it inside individual tbody its because I also have a button to be able to move the 1st tbody to the bottom/last of the table. 你们中的很多人都质疑上面的桌子结构,但是我之所以将它放在单独的琴体内是主要原因,因为我还有一个按钮可以将第一个琴体移到桌子的底部/最后。

I use PHP to display records 我使用PHP显示记录

see output below ,Use this 参见下面的输出,使用它

It Will hide all the toprowHeaders except the first one as per your requirement 它会隐藏除您需要的第一个toprowHeader之外的所有toprowHeader

  $('tr.toprowHeader:gt(0)').hide(); $('table').append($('tbody:eq(0)')); console.log($('tbody:eq(0)')); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table class="gridtable"> <tbody> <tr class="toprowHeader" > <td class="">title 1</td> </tr> <tr class="recordsRow " > <td class="">record1</td> </tr> <tr class="recordsRow " > <td class="">record1</td> </tr> </tbody> <tbody> <tr class="toprowHeader"> <td class="">title2</td> </tr> <tr class="recordsRow "> <td class="">record2</td> </tr> <tr class="recordsRow "> <td class="">record2</td> </tr> </tbody> <tbody> <tr class="toprowHeader"> <td class="">title3</td> </tr> <tr class="recordsRow "> <td class="">record3</td> </tr> <tr class="recordsRow "> <td class="">record3</td> </tr> </tbody> <tbody> <tr class="toprowHeader"> <td class="">title4</td> </tr> <tr class="recordsRow "> <td class="">record4</td> </tr> <tr class="recordsRow "> <td class="">record4</td> </tr> </tbody> <tbody> <tr class="toprowHeader"> <td class="">title5</td> </tr> <tr class="recordsRow "> <td class="">record5</td> </tr> <tr class="recordsRow "> <td class="">record5</td> </tr> </tbody> <tbody> <tr class="toprowHeader"> <td class="">title6</td> </tr> <tr class="recordsRow "> <td class="">record6</td> </tr> <tr class="recordsRow "> <td class="">record6</td> </tr> </tbody> <tbody> <tr class="toprowHeader"> <td class="">title7</td> </tr> <tr class="recordsRow "> <td class="">record7</td> </tr> <tr class="recordsRow "> <td class="">record7</td> </tr> </tbody> </table> 

You can use CSS as shown below: 您可以使用CSS,如下所示:

 tbody:not(:first-child) .toprowHeader{ display: none; } 
 <table class="gridtable"> <tbody> <tr class="toprowHeader"> <td>Title</td> </tr> <tr class="recordsRow "> <td>Record</td> </tr> <tr class="recordsRow "> <td>Record</td> </tr> </tbody> <tbody> <tr class="toprowHeader"> <td>Title</td> </tr> <tr class="recordsRow "> <td>Record</td> </tr> <tr class="recordsRow "> <td>Record</td> </tr> </tbody> </table> 

By the way, You should really try modifying the script to omit the extra titles instead (whichever generates it), and have a single title row inside <thead> 顺便说一句,您应该真正尝试修改脚本以省略多余的标题(以生成它的人为准),并且在<thead>有一个标题行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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