我想导出p-datatable中的特定列。我以前导出过所有记录,但现在我想导出特定的列。我该怎么做?
答案 0 :(得分:0)
要从csv中排除列,请使用[exportable] =" false"在p柱上。
答案 1 :(得分:0)
要获取特定的列,有一个解决方案。 HTML页面:
<p-dataTable #dg [value]="groupdetails" selectionMode="multiple" resizableColumns="true" reorderableColumns="true" expandableRows="true" [paginator]="true" [rows]="5" [pageLinks]="3" [rowsPerPageOptions]="[5,10,20]" [loading]="ploader3">
<p-header>
<div class="ui-helper-clearfix">
<button class="btn btn-info" type="button" (click)="dg.exportCSV({selectionOnly:true})" style="float:left"><i class="fa fa-download" aria-hidden="true"></i> SELECTED EXPORT</button>
<button class="btn btn-info" type="button" (click)="export(dg)" style="float:right"><i class="fa fa-download" aria-hidden="true"></i> Export</button>
</div>
</p-header>
<p-column field="groupName" [filter]="true" [sortable]="true" header="groupName"></p-column>
<p-column field="groupId" [filter]="true" [sortable]="true" header="groupId"></p-column>
<p-column field="parentGroupId" [filter]="true" [sortable]="true" header="parentGroupId"></p-column>
</p-dataTable>
在“ TS”页面中:
public export(e){
const hiddenColumns: any[] = [];
e.columns.forEach((c) => {
if (c.field === "hiddencolumnName" ) {
hiddenColumns.push({field: c.field, col: c});
c.field = '';
} if (c.field === "hiddencolumnName2" ) {
hiddenColumns.push({field: c.field, col: c});
c.field = '';
}
}
e.exportCSV();
// restore their fields so still works in the future
hiddenColumns.forEach((hc) => {
hc.col.field = hc.field;
});
}
将列添加到不想导出的隐藏数组中。