国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

如何將p-table的高度調(diào)整為與視窗高度相同
P粉132730839
P粉132730839 2023-08-25 12:06:40
0
1
789
<p><strong>問(wèn)題:</strong> 我正在嘗試在angular中設(shè)定一個(gè)prime p-table的高度。我已經(jīng)在網(wǎng)上搜索了很多結(jié)果,但到目前為止都沒(méi)有起作用(可能是由於這個(gè)問(wèn)題存在多年,並且對(duì)框架進(jìn)行了一些更改,禁用了某些解決方案)。 </p> <p>我已經(jīng)嘗試了兩種方法,第一種方法在下面的程式碼中。第二種方法是將p-table的父div的高度設(shè)定為innerWindowHeight,並將p-table的scrollheight設(shè)定為flex(也不行)。 </p> <p><strong>工具:</strong>Angular 14.2.0與PrimeNG 14.1.1在一個(gè)新專案</p> <p>我在<strong>app.component.html</strong>有以下html代碼:</p> <pre class="brush:php;toolbar:false;"><div> <p-table #table (window:resize)="onResize()" [value]="data" [paginator]="true" [showCurrentPageReport]="true" [scrollable]="true" [scrollHeight]="tableScrollHeight" [rows]="10" [rowsPerPageOptions]="rowsPerPage" styleClass="p-datatable-gridlines p-datatable-striped p-datatable-sm" currentPageReportTemplate="{first} to {last} of {totalRecords} records"> <ng-template pTemplate="header"> <tr> <th>日期</th> <th>ID</th> <th>描述</th> <th>值</th> <th>稅</th> </tr> </ng-template> <ng-template pTemplate="body" let-entry> <tr> <td>{{entry.date}}</td> <td>{{entry.id}}</td> <td>{{entry.description}}</td> <td>{{entry.value}}</td> <td>{{entry.tax}}</td> </tr> </ng-template> </p-table> </div></pre> <p>以及以下的<strong>app.component.ts</strong>:</p> <pre class="brush:php;toolbar:false;">import {Component} 從 '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'Testapp'; data: any[]; tableScrollHeight: string = "700px"; rowsPerPage: number[] = [5, 10, 20, 50]; constructor() { this.data = []; let entry: any = {}; entry.description = "First entry"; this.data.push(entry); } onResize() { this.tableScrollHeight = window.innerHeight 'px'; } }</pre> <p><strong>我想要實(shí)現(xiàn)的行為:</strong> 我希望無(wú)論表格是否為空或沒(méi)有足夠的條目來(lái)填充窗口,分頁(yè)器都保持在窗口底部,並且當(dāng)表格行大於螢?zāi)淮笮r(shí),表格可以滾動(dòng)(頭部保持在頂部)。 </p> <p>為了澄清我想要實(shí)現(xiàn)的目標(biāo),這裡有一個(gè)截圖展示它的當(dāng)前狀態(tài): 目前狀態(tài)</p> <p>這裡有一個(gè)截圖展示我希望它看起來(lái)的樣子: 應(yīng)該的樣子</p> <p><strong>問(wèn)題:</strong> 有沒(méi)有辦法以乾淨(jìng)的方式達(dá)成這個(gè)目標(biāo)? </p> <p>如評(píng)論中建議的那樣,我添加了一個(gè)<strong>stackblitz</strong>:https://angular-ivy-sfk7pw.stackblitz.io</p> <p><strong>編:</strong> 我發(fā)現(xiàn)如果將table的scrollHeight設(shè)定為表格內(nèi)部的一個(gè)<strong>div</strong>(由primeng產(chǎn)生),該div的類別名稱為<strong>p-datatable-wrapper</strong>,它會(huì)取得樣式"<strong>max-height</strong>: <strong>XXX</strong>px",其中<strong>XXX</strong>是<strong>tableScrollHeight的值</strong> 。我可以寫一個(gè)CSS選擇器將樣式更改為min-width,但這可能不是一個(gè)好主意,因?yàn)槲覍⒉坏貌粡膖ypscript文件中訪問(wèn)dom並蒐索自動(dòng)生成的div。 </p>
P粉132730839
P粉132730839

全部回覆(1)
P粉529581199

也許你可以嘗試將這個(gè)樣式加入你的 css/scss 中,但這不是最佳實(shí)踐。

.p-datatable-wrapper {
  min-height: calc(100vh - 90px);
}

注意: 100vh 是你的螢?zāi)桓叨龋?code>90px 是一個(gè)範(fàn)例的分頁(yè)高度。

就是這樣。希望能對(duì)你有幫助。

最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板