3

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.)

  • 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. – Caspar Harmer Apr 13 '18 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 Apr 13 '18 at 21:41
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.

  • 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 Apr 13 '18 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 Apr 13 '18 at 19:05

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.