0

Below is my lightning datatable

<lightning:datatable columns="{!v.myclmns}"
                           data="{!v.mydata}"
                           keyField="id"
                           selectedRows="{!v.selectRow }"
                           onrowselection="{!c.getSelection }
                           hideCheckboxColumn="false"/>

How can i disable the checkbox or make it unclickable for a particular row based on certain conditions?

For example, i have country in my data, i want to disable the checkbox in the row if the country is not USA. Thanks in Advance!!

  • Please share your code which you have tried so far. – Dhanik Lal Sahni Jun 20 at 7:36
0

I can suggest you to use a custom data type. You can read more about that here.

In that case, you just expand base LightningDatatable class and add your own type (customDataTable.js):

import LightningDatatable from 'lightning/datatable';
import checkBoxCellView './checkBoxCellView.html';

export default class customDataTable extends LightningDatatable {
    static customTypes = {
        checkBoxCell: {
            template: checkBoxCellView,
            typeAttributes: ['isChecked', 'isDisabled'],
        }       
    };
}

Then you use it as a new component (template.html):

<c-custom-data-table key-field="id" data={proxyFiles} columns={columns} onrowselection={handleSelection}
            onrowaction={handleAction} selected-rows={selectedRows} onsort={updateColumnSorting}
            sorted-direction={sortDirection} sorted-by={sortBy}>
</c-custom-data-table>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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