0
<p-column header="Actions" selectionMode="multiple" [style]="{'width':'40px'}" ></p-column>

I have added above line which causes multiselection mode on in my priming datatable. but I want to disable certain checkboxes depend on condition. How to handle this? I tried same using [rowstyleclass] but it has performance issue since it get called evereytime I hover mouse on particular row. Any solution?

user19041992
  • 133
  • 1
  • 5
  • 18

2 Answers2

2

You can use templating to achieve that. Just disable the checkboxes based on your condition in the template, and you should be good to go.

2

You can Use column template to achieve this. here is sample code.

Here all even number rows are disabled with logic - [disabled]="item.Id%2 == 0" , You can put your required logic in place.

your.component.html

<p-dataTable #dt [value]="persons">
 <p-column field="" header="Select" [style]="{'width':'60px', 'align-items':'center'}">
   <ng-template let-col let-item="rowData" pTemplate="body">
      <p-checkbox [disabled]="item.Id%2 == 0" 
                  [style]="{'align':'center'}" 
                  name="persongroup" 
                  [value]="item" 
                  [(ngModel)]="selectedPersons">
      </p-checkbox>
   </ng-template>
 </p-column>
 <p-column field="Id" header="Id"></p-column>
 <p-column field="Name" header="Name"></p-column>
</p-datatable>

your.component.ts

persons : Person[] = [
                        {'Id' : 1, 'Name' :     'person1'},
                        {'Id' : 2, 'Name' :     'person2'}
                     ];
selectedPersons : Person[]=[];
TimeTraveler
  • 1,223
  • 12
  • 15