2

I am busy learning how to use ngx data tables in Ionic apps(Using angular), and I need to be able to ad an edit and delete button to each row.

I have seen people use templates but I am not sure how this works, I make an API call and display the data as usual using

<ngx-datatable class="material"
[rows]="rowdata"
[columns]="columndata">
</ngx-datatable>

But now I need an extra column with an edit and delete button that takes the ID from each row and passes it to an edit and delete function in the .ts file.

How does one go about doing this?

Thanks R

1 Answer 1

3

You need to define new column name Actions with prop Id as targetting value. and also need each column to be declared inside ngx-datatable

HTML code

    <ngx-datatable class="material"
      [rows]="rowdata"
      [columns]="columndata">


 <ngx-datatable-column name="Actions" prop="name">
   <ng-template ngx-datatable-cell-template let-rowIndex="rowIndex" let-value="value"
                                    let-row="row">
                                    <button type="button" class="btn btn-outline-success"
                                        (click)='edit(value)'>Success {{rowIndex}}</button>
                                    <button type="button" class="btn btn-outline-danger"
                                        (click)='delete(value)'>Danger</button>


              </ng-template>
          </ngx-datatable-column>
  <ngx-datatable-column name="Name" prop='name' >
           </ngx-datatable-column>  // need to define each column with empty body

</ngx-datatable>

TS code

columns = [ ... { name: 'Actions', prop: 'Id' } //new column to existing column array  ***define prop to Id 
  ];


  edit(value) {
    console.log(value);
  }


  delete(value) {
    console.log(value);
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.