8

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?

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

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.

4

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

  • 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? – Robert Sösemann Jan 28 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 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. – Robert Sösemann Jan 30 at 14:27

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.