PrimeNG角度数据表加载字符串数组

时间:2019-05-13 17:00:39

标签: angular primeng

我是PrimeNG Datatable网格的新手。最初,我的网格具有与网格紧密关联的属性:

                            <p-column
                                field="ColShortName"
                                header="Select a Column"
                                [sortable]="true"
                                [filter]="true"
                                filterPlaceholder="Search"
                                filterMatchMode="contains"
                            >
                            </p-column>

但是现在我将基础数据数组更改为仅是字符串数组:

[“ Component.O_Account_Period”,“ Component.O_Account_Period_Commencement_Date”,..]

现在在网格中,我在读取数据时看到一堆空行,但是我不知道用什么替换该字段?

如果我的数组没有任何属性怎么办?

HTML:

<div class="form-group col-xs-12">
    <p-dataTable
        appAutoFocus
        [value]="columnDefinitionData"
        sortMode="multiple"
        [multiSortMeta]="multiSortMeta"
        [scrollable]="true"
        scrollHeight="150px"
        (onRowSelect)="onEdit($event)"
        selectionMode="single"
        [(selection)]="selectedItem"
    >
        <p-column
            header="Select a Column"
            [sortable]="true"
            [filter]="true"
            filterPlaceholder="Search"
            filterMatchMode="contains"
        ></p-column>
    </p-dataTable>
</div>

.ts:

public columnDefinitionData: string[] = [];

private loadColumnDefinitions() {
    this._directUpdateService.getColumnDefs().subscribe(
        r => {
            this.columnDefinitionData = r;
            for (let i = 0; i <= this.logs.length - 1; i++) {
                if (
                    this.logs[i].wfWorkflowStatus ===
                        "CDS2 Validation Failed" ||
                    this.logs[i].wfWorkflowStatus === "Ready for Review"
                ) {
                    this._disableAdd = false;
                }
            }
        },
        e => {
            throw e;
        }
    );
}

service.ts:

public getColumnDefs(): Observable<string[]> {
    return this._http.get(`${this._columnDefinitionUrl}GetDbTableCDS2`);
}

如您所见,网格中填充了行,但未显示数据。我还需要此名称才能进行搜索。当我使用对象时,我可以搜索。

enter image description here

0 个答案:

没有答案