4

A click on a table cell in a basic lightning:datatable highlights the cell border but does not select the row. For the common case where the table is just listing read-only data, being able to click/touch anywhere in the row would seem a usability benefit particularly on a mobile device. I don't see an onclick or similar attribute to hook code to.

Is there some simple configuration or code that will get the row selected when a table cell is clicked?

(Resorted to this Angular Selection Model for a similar need in an Angular project.)

2
  • 1
    I have built a datatable implementation that can handle clicks and variable columns. The only limitation is that you must pre-format the table values as it's not set up handle different data display types. It's blindingly fast though. Lemme know if you want to take a look. Commented Apr 13, 2018 at 20:38
  • 1
    @CasparHarmer Thanks! At the moment this isn't critical enough for me to step away from the "out of the box" component but I do appreciate the offer.
    – Keith C
    Commented Apr 13, 2018 at 21:41

2 Answers 2

3

No. Essentially, because of Locker Service, the lack of a rowclick handler, or even the ability to put your own custom template inside the body of the component, there is absolutely no way to get an event fired that can tell you which row was clicked on. Long story short, is if you're going to do this, you're going to have to write your own data table implementation.

2
  • Thanks. Seems like there is an opportunity for someone other than Salesforce to write a really good table/grid component, but I guess the fear would be that in a year's time Salesforce will get this one up to a standard where it does most of what people need.
    – Keith C
    Commented Apr 13, 2018 at 19:04
  • 1
    @KeithC I'm working on my own library right now, actually, but yes, every time I get around to writing something cool, Salesforce adds it to the native code base.
    – sfdcfox
    Commented Apr 13, 2018 at 19:05
2

You can extend datatable and setup event listeners that can then capture a row id. Our team followed this tutorial to get ours working with some minor modifications

You must log in to answer this question.

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