12

I have a nice LWC component which is using lightning-datatable but I also need InlineEdit for those two types which are currently not supported.

  • Lookup Field
  • Picklist Field

Option A: I could use the Open Source code of the data table for https://github.com/salesforce/base-components-recipes and add the two missing inline-edit features. WON'T WORK as the data table is not available!

Option B: Wait until Salesforce offers support. WON'T WORK as nobody can tell me if it will ever happen.

Option C: Build my own Custom Data table with support for everything that I need. WON'T WORK as is takes years to build a good and powerful datatable.

Feels a bit like Groundhog Day again. When Aura came out Developer also found the Base Data Table to not be flexible or powerful enough and build zillions of quirky custom components on Github. Are we forced to repeat this or is there any other alternative?

1
  • This is all great info, but I am really hoping SF will do the right thing and get Option B working. Jan 30, 2020 at 13:19

2 Answers 2

8

Option B.

  • Option A is not an option until B happens first
  • you mention C would take years and I believe it'll be open-sourced before then

The reason for this optimism is that they actually asked this to the Director of Product Management for Lightning at the developer preview live for Spring 20.

Fast-forward to 1:07:50 to hear the question and answer for yourself.

He basically said that lightning-datatable was the first LWC base component they made while they were building the framework for LWC. This means they made some wrong decisions and they're going through the process to clean it up (for best practices) to open source it. Also mentioned it's the most complex component they have.

However, most importantly, he reiterated it's absolutely on their roadmap.

2
  • Great find. Thank you. Jan 28, 2020 at 13:54
  • 1
    Fun fact: if in a Summer '21 preview sandbox you add a column to your LWC datatable with type = reference you will notice an element called lightning-formatted-lookup being added to your table. It doesn't seem to work yet, or at least I didn't get it to work. It looks like it's actively being worked on.
    – Steven.B
    May 31, 2021 at 15:15
5

One other option you can take is it use the Datatable's Custom Data Type and the lightning-record-edit-form. Using the Custom Data Type (CDT) allows you to represent a column's data in the manner you desire.

How I have done it is to set up a CDT (e.g. picklist) to ingest the record id, record type id, targeted object, and the picklists that I'm targeting (you must include all controlling picklist). In the the CDT's template, I am invoking the lightning-record-edit-form to generate the picklists (used this as it supports dependency). I also overrode the lightning-record-edit-form's save function to check if the user selected other rows in the data table and to apply the save to all selected rows.

This does require a fair amount of development but you should be able to accomplish most of the targeted object setup (picklist, fields, etc) using the Schema class in Apex. The only part that was tricky was setting up the JSON object used for the CDT.

Documentation for CDT found here

3
  • Awesome answer and I guess you are a Salesforce employee who saw my tweet about this. The linked documentation basically says nothing so would you mind eighter linking some open-source code for the use of CDTs or share some minimalized code in your answer so I can work from it to our picklist or lookup implementation? Jan 28, 2020 at 16:58
  • 1
    I'm not a SF employee, just another developer who's hit this issue since aura. I currently do not have any minimalized or open source code to share, but may add later. In the documentation (~3/4 down) they give an example on setting up the CDT. The example provided only works if the CDT is used once per row. What I did with that example was have the cell value use a nested JSON object that had the typeAttributes store in there rather than at the row level. In the definition of the CDT, I used typeAttributes: ['value.tA.targetFields','value.tA.recordId','value.tA.sObj']
    – MarkyMark
    Jan 28, 2020 at 22:58
  • I found a fully working example here: github.com/atskimura/… but I am unsure if this would really work for building an Inline Edit Mode for a Picklist. Jan 30, 2020 at 14:27

You must log in to answer this question.

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