2

My component fills the lightning:datatable with no problems.

I wanted to capture the onrowselection but couldn't get it to work. I had the hideCheckboxColumn="false" but didn't see any checkboxes. I removed the hideCheckboxColumn="false" and now I see checkboxes and when I click a checkbox the onrowselection fires.

Is this how the onrowselection works for a lightning:datatable?

Before I used a UL list and set the onclick on each LI and it worked fine.

2 Answers 2

2

Yes, it only works on the checkboxes. Unfortunately, there is no onrowclick type handler as there was in Visualforce right now. If you want to make a Lightning Data Table that has this feature, you're going to have to write your own component(s) to do this.

2

One solution which you might consider is setting maxRowSelection="1" in your lightning:datatable - this way you won't get a clickable row but you will get a radio button on each row and upon selecting it you can retrieve selected row data like this:

    selectRow: function (component, event, helper) {
        var selectedRows = event.getParam("selectedRows");
        console.log('selectedRow: ' + JSON.stringify(selectedRows));
    }

This solution resembles onrowclick to the greatest extent available without actually using something else rather than Lightning Datatable.

1
  • 1
    Works like a charm!! Commented Jan 2, 2020 at 13:01

You must log in to answer this question.

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