MHOOS
MHOOS

Reputation: 5306

Binding boolean column to checkbox in ngx-datatable

How can I bind a Boolean column to a checkbox in ngx-datatable? Currently I am using angular material table and use the following method :

  <ng-container matColumnDef="Active">
    <mat-header-cell *matHeaderCellDef class="generic-centeredCell"> Active </mat-header-cell>
    <mat-cell *matCellDef="let element" class="generic-centeredCell">
      <span class="mobile-label">Active:</span>
      <mat-checkbox [(ngModel)]="element.active"></mat-checkbox>
    </mat-cell>
  </ng-container>

How can I make use of above code when I move to ngx-datatable? I cant event find a sample. The only samples I have seen so far is http://swimlane.github.io/ngx-datatable/#chkbox-selection which doesn't explain how to bind the boolean column to a checkbox.

Upvotes: 0

Views: 4658

Answers (1)

MHOOS
MHOOS

Reputation: 5306

I found the answer to my own question and I thought it might help someone in future. Above code would translate to something similar to below :

  <ngx-datatable-column name="Active">
    <ng-template ngx-datatable-cell-template let-value="value">
      <mat-checkbox [(ngModel)]="value"></mat-checkbox>
    </ng-template>
  </ngx-datatable-column>

Simply just put the control inside

using this method not only allows you to have Boolean column bound to checkbox, you can also embed other controls inside the column.

Upvotes: 3

Related Questions