[SalesForce] How to disable the checkboxes for specific rows on lightning:datatable

I have a lightning:datatable component:

<lightning:datatable columns="{!v.columnsPhone}"
                           data="{!v.dataPhone}"
                           keyField="id"
                           selectedRows="{!v.selectedRowsPhone }"
                           onrowselection="{!c.getSelectedPhone }
                           hideCheckboxColumn="false"/>

I'm looking to disable the checkboxes just for specific rows based on some conditions.

The documentation for lightning:datatable doesn't talk about disabling checkbox for some rows.

How can I disable the checkboxes on specific rows?

Best Answer

Just for the information.

I had the same issue and as a workaround I implemented following.

Note: I was using lightning web components

JS Code

@track selectedRowIds = [];

onRowSelection(event) {
    var rows = event.detail.selectedRows;
    this.selectedRows = [];
    this.selectedRowIds = [];
    rows.forEach(row => {
        if(!mycondition_to_disable) {
            this.selectedRowIds.push(row.Id);
        }
    });
}

HTML Code

<lightning-datatable onrowselection={onRowSelection}>
</lightning-datatable>

Then if your condition is met, you cannot select that particular row.