4

I am new to LWC and I'm trying to learn by converting an older Aura component to a LWC. What I'm trying to do right now is conditionally add the "show-row-number-column" attribute to the lightning-datatable via JavaScript.

In Aura I could set showRowNumberColumn = "{! c.enableRowNumber}" (which would pull in true or false conditionally), but in the LWC it looks like I have to add or remove the whole attribute from the datatable not just set it to true or false. I've searched, but don't see any way to conditionally add or remove an attribute from the datatable. Would someone be able to point me in the right direction here?

1 Answer 1

6

Although it is true that you have to just mention the attribute to make it true in LWC, this is applicable only to pass static value true and if you want to make it dynamic you can bind it to tracked property in LWC also (like Aura).

show-row-number-column={enableRowNumber}

Here show-row-number-column will become true or false depending on tracked property enableRowNumber.

PROOF: You can this playground link - created an example for your understanding

1
  • 1
    Thank you! I actually tried that previously but must have had some other issue. I was able to get it to work in my component by following/extending your example in the playground. Thank you again.
    – Tim Wilson
    Commented Sep 13, 2019 at 14:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .