问题
I am working on an angular project where I am using ngx-datatables to show data in tables. Here I am trying to add edit(not inline) and delete functionality in it.
I have created a template to use in edit and refer it in cellTemplate of column's array. But I am getting EmployeeId in this cellTemplate, may be I have not proceed it the way it should work.
How to get the edit icon and pass routerLink property with related EmployeeId value to each anchor tag in the template.
<ngx-datatable class="material striped"
[columns]="columns"
[columnMode]="'force'"
[rows]="gridModel.Data"
[headerHeight]="'auto'"
[footerHeight]="'auto'"
[rowHeight]="'auto'"
[externalPaging]="gridModel?.isServerSide"
[externalSorting]="gridModel?.isServerSide"
[count]="gridModel?.TotalElements"
[offset]="gridModel?.CurrentPageNumber"
[limit]="gridModel?.PageSize"
[loadingIndicator]="gridModel?.isLoading"
(page)='loadPage($event)'
(sort)="onSort($event)"
[targetMarkerTemplate]="targetMarkerTemplate"
[reorderable]="gridModel?.reorderable"
[swapColumns]="gridModel?.swapColumns">
<ngx-datatable-column *ngFor="let col of columns"
[name]="col.name" [prop]="col.prop">
</ngx-datatable-column>
</ngx-datatable>
<ng-template #idAnchorEditTemplate let-row="row" let-value="value">
<a [routerLink]="['edit', value]" class="btn btn-sm btn-outline-primary">
<i class="fa fa-pencil" aria-hidden="true"></i>
</a>
</ng-template>
@ViewChild('idAnchorEditTemplate')
public idAnchorEditTemplate: TemplateRef<any>;
this.grid.columns = [
{ name: 'Employee Id', prop: 'EmployeeId' },
{ name: 'Name', prop: 'Name' },
{ name: 'City', prop: 'City' },
{ name: 'Department', prop: 'Department', sortable: false },
{ name: 'Gender', prop: 'Gender', sortable: false },
{
cellTemplate: this.grid.idAnchorEditTemplate,name:'Edit', prop: 'EmployeeId' ,width: 100
}
];
来源:https://stackoverflow.com/questions/51303630/how-to-use-edit-and-delete-options-in-angular-ngx-datatables