0

当我使用文档中的此代码时,它适用于根模块,但我想在延迟加载的模块中做同样的事情?当我尝试在延迟加载的模块上重新排序表时,它会冻结。我查看了导入,一切都很好,所以如果有人遇到同样的问题,请帮助:)。

HTML

 <p-table [value]="products" [columns]="cols" [reorderableColumns]="true" responsiveLayout="scroll">
    <ng-template pTemplate="header" let-columns>
        <tr>
            <th style="width:3rem"></th>
            <th *ngFor="let col of columns" pReorderableColumn>
                {{col.header}}
            </th>
        </tr>
    </ng-template>
    <ng-template pTemplate="body" let-rowData let-columns="columns" let-index="rowIndex">
        <tr [pReorderableRow]="index">
            <td>
                <span class="pi pi-bars" pReorderableRowHandle></span>
            </td>
            <td *ngFor="let col of columns">
                {{rowData[col.field]}}
            </td>
        </tr>
    </ng-template>
</p-table>

TS:

import { Component, OnInit } from '@angular/core';
import { Product } from '../../domain/product';
import { ProductService } from '../../service/productservice';

@Component({
    templateUrl: './tablereorderdemo.html'
})
export class TableReorderDemo implements OnInit {

    products: Product[];

    cols: any[];

    constructor(private productService: ProductService) { }

    ngOnInit() {
        this.productService.getProductsSmall().then(data => this.products = data);

        this.cols = [
            { field: 'code', header: 'Code' },
            { field: 'name', header: 'Name' },
            { field: 'category', header: 'Category' },
            { field: 'quantity', header: 'Quantity' }
        ];
    }
} 

https://www.primefaces.org/primeng/showcase/#/table/reorder

4

0 回答 0