我在角度4应用程序中使用swimlane/ngx-datatable
设置了一个表格。该表使用属性scrollbarV
,因为它是必需的必需项。我想完全按照他们提供的example进行操作,并使用滚动条为表格设置固定高度。在附加的资料中,我们不清楚(对我而言)他们如何设置桌面高度。所以我的问题是,整个表的高度是如何设置/定义的?
示例来源:
import { Component } from '@angular/core';
import {MockServerResultsService} from "./mock-server-results-service";
import {PagedData} from "./model/paged-data";
import {CorporateEmployee} from "./model/corporate-employee";
import {Page} from "./model/page";
@Component({
selector: 'virtual-paging-demo',
providers: [
MockServerResultsService
],
template: `
<div>
<h3>
Virtual Server-side Paging
<small>
<a href="https://github.com/swimlane/ngx-datatable/blob/master/demo/paging/paging-virtual.component.ts" target="_blank">
Source
</a>
</small>
</h3>
<ngx-datatable
class="material"
[rows]="rows"
[columns]="[{name:'Name'},{name:'Gender'},{name:'Company'}]"
[columnMode]="'force'"
[headerHeight]="50"
[scrollbarV]="true"
[footerHeight]="50"
[rowHeight]="50"
[externalPaging]="true"
[count]="page.totalElements"
[offset]="page.pageNumber"
(page)='setPage($event)'>
</ngx-datatable>
</div>
`
})
export class VirtualPagingComponent {
page = new Page();
rows = new Array<CorporateEmployee>();
cache: any = {};
constructor(private serverResultsService: MockServerResultsService) {
this.page.pageNumber = 0;
}
/**
* Populate the table with new data based on the page number
* @param page The page to select
*/
setPage(pageInfo) {
this.page.pageNumber = pageInfo.offset;
this.page.size = pageInfo.pageSize;
// cache results
// if(this.cache[this.page.pageNumber]) return;
this.serverResultsService.getResults(this.page).subscribe(pagedData => {
this.page = pagedData.page;
// calc start
const start = this.page.pageNumber * this.page.size;
// copy rows
const rows = [...this.rows];
// insert rows into new position
rows.splice(start, 0, ...pagedData.data);
// set rows to our new rows
this.rows = rows;
// add flag for results
this.cache[this.page.pageNumber] = true;
});
}
}
答案 0 :(得分:3)
与链接中的示例相关联的来源(http://swimlane.github.io/ngx-datatable/#virtual-paging)具有误导性。
在这个例子中,有几件事掩盖了如何计算高度:
vh
单位,这些单位是视口比例。垂直调整示例窗口的大小会自动导致对示例高度的相应更改。设置固定高度的最常用方法是使用style
属性或样式表规则。使用style
属性,您可以在style="height: 300px;"
定义中添加ngx-datatable
之类的内容。或者,您可以设置定位.ngx-datatable
的规则或执行更精细的操作,例如添加id
属性并将其定位,然后添加样式以设置高度。
以下是样式属性在应用于您的代码段时的外观。
<ngx-datatable
class="material"
style="height: 300px;"
[rows]="rows"
[columns]="[{name:'Name'},{name:'Gender'},{name:'Company'}]"
[columnMode]="'force'"
[headerHeight]="50"
[scrollbarV]="true"
[footerHeight]="50"
[rowHeight]="50"
[externalPaging]="true"
[count]="page.totalElements"
[offset]="page.pageNumber"
(page)='setPage($event)'>
</ngx-datatable>
答案 1 :(得分:0)
这对我有用
<ngx-datatable
#table
class="material common-m-tbl"
[columns]="columnList"
[columnMode]="ColumnMode.force"
[virtualization]="false"
[headerHeight]="50"
[footerHeight]="footerHeight"
rowHeight="36"
[scrollbarV]="true"
[rows]="rows"
[messages]="messages"
[externalPaging]="true"
[count]="page.totalElements"
[offset]="page.pageNumber"
[limit]="page.size"
(page)="setPage($event)"
[selectionType]="SelectionType.single"
(sort)="onSort($event)"
(activate)="onActivate($event)"
[messages]="messages"
style="height: 530px;"
>