0

I have a following data in a List,

From the following data I will create the native lightning datatable and it looks like follows

0: {Name: "Test Contact 2", Person__c: "a0j4E00000BY96GQAT"}
1: {Name: "Test Contact 1", Person__c: "a0j4E00000BY96GQAT"}

enter image description here

Afterwards I just selected the Contacts which I need to generate the Requests and when I click the Button the datatable will looks like below,

enter image description here

In the above datatable I'll need to disable the Test Contact 2 row to select because its status is Pending.

According to the above data I'll need to show those data in a datatable in a lightning component. What I need here is in that datatable I'll need to disable a particular row according to the record status__c field.

Is it possible in datatable? I couldn't find any place to refer it.

For a workaround I just hide the checkbox column if all records status are Pending and I used a Trigger to avoid creating the pending request again to a particular Contact and according to the results I did something to achieve what I need. But its very easy If we have a way to disable row wise.

  • Hi, if possible try conditional styling. which ever row has status value that's not supposed to be selected, grey-out the row by applying style from Javascript and disable the checkbox beside that row. – 7'7' Mar 20 at 11:25
  • Does "disable" just mean not include row actions, here? Are you using the native <lightning:dataTable> component, and if so what does your markup look like? Could you edit your question to add some more details? – David Reed Mar 20 at 11:29
  • @DavidReed, Yes and also need to disable to check the checkbox, yes. I have edited. – Hariprasath Mar 20 at 11:56
0

If you want to decide which button to disable for each row, you can handle it like this:

When you set your button column (oninit) set it's disabled attribute to a fieldName:

{label: 'myButton', fieldName: 'click', type: 'button', typeAttributes: {label:  'myButton',
                                                                        name: 'typeButton',
                                                                        disabled: {fieldName: 'typeButton_disabled'}}},

Then after you get your data, go over all rows and decide for each one what is the disabled status you want to give the button, and set the typeButton_disabled field accordingly:

for (var i=0; i<data.length; i++) {

    if (you want to disable the button for this row) {
        data[i].typeButton_disabled = true;
    }
    else {
        data[i].typeButton_disabled = false;
    }
}

Now save your data to the attribute.

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.