3

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?

0

Just for the information.

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

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.