How to use edit and delete options in Angular NGX-Datatables

倾然丶 夕夏残阳落幕 提交于 2019-12-11 16:32:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!