Creating a custom datatable in Salesforce that allows editing a Time field

Viewed 394

I'm creating a custom lightning-datatable component where I want to display some fields from a custom object I created. One of those fields to display, Start_Time__c, is of type Time.

I figured out from the documentation to show this field I need to use type 'date' in my column definition within lightning-datatable (please tell me if I'm wrong here and there is a better way to just display the time).

I have everything displaying fine, and can update my code to allow the Start_Time__c column to be editable.

The issue is I get an error when trying to save when I actually do edit the cell containing a Start Time.

My save handler looks like this (copied mostly from documentation):

const fields = {};
         fields[ID_FIELD.fieldApiName] = event.detail.draftValues[0].Id;
         fields[START_TIME.fieldApiName] = event.detail.draftValues[0].Start_Time__c;

         const recordInput = {fields};
         
          updateRecord(recordInput).then(() => {
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Success',
                    message: 'Contact updated',
                    variant: 'success'
                })
            );

            // Display fresh data in the datatable
            return refreshApex(this.agendaItems).then(() => {
                // Clear all draft values in the datatable
                this.draftValues = [];
            });
          }).catch(error => {
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Error updating or reloading record',
                    message: error.body.message,
                    variant: 'error'
                })
            );
          });

When I try to save, I get this error: Value for field 'Start_Time__c' is not in ISO 8601 format, Value: 1970-01-01T15:00:00.000Z, Runtime class: java.lang.String"

I would assume passing in the value I get back from the datatable when the field was edited should work, since I'm just passing the updated fields from the save event.

How do I properly handle this Time field (which is coming in as a DateTime due to datatable only supporting the date type)?

0 Answers
Related