1

When i click of Inline edit Data table page got refreshed in LWC with Visualforce page. Can anyone help me what I'm missing below.

HTML:

template>
<lightning-record-edit-form record-id={recordId} object-api-name="Enrollment__c"  >
<lightning-datatable key-field="Id" data={data} columns={columns}
                                draft-values={draftValues} hide-checkbox-column="true"  
                                resize-column-disabled="true">
                            </lightning-datatable>
                            </lightning-record-edit-form>

JS

import { LightningElement, api, wire, track } from "lwc";
import { getRecord} from "lightning/uiRecordApi";

import getParentdetails from "@salesforce/apex/GetParentGuardianController.getParentdetails";

const columns = [
  { label: "First Name", fieldName: "FirstName", editable: true },
 { label: "Last Name", fieldName: "LastName" },


 { label: "Phone", fieldName: "Phone", type: "phone" },
 { label: "Email", fieldName: "Email", type: "email" },
 { label: "Student Relation", fieldName: "Student_Relation__c" }
];
export default class TestProject extends LightningElement {
@api recordId = "a082w000000YUH5AAO";

@track columns = columns;

@wire(getRecord, { recordId: "$recordId" })
contact;

@track error;
@track data;

@wire(getParentdetails, { enrollmentName: "a082w000000YUH5AAO" })
getContacts(response) {
  console.log('one');
  const data = response.data;
  const error = response.error;
  if (data) {
    this.data = data;
  } else if (error) {
    this.error = error;
  }
}
}
1

You page is refreshing because you are using data table in record Edit form, so instead of using record edit form use onSave method of data table to save the record you can do this :

HTML

<lightning-datatable key-field="Id" data={data} columns={columns}
                            draft-values={draftValues} hide-checkbox-column="true"  
                            resize-column-disabled="true"
                            onsave={handleSave}>
                        </lightning-datatable>

JS

    handleSave(event){
      //here invoke apex and pass draftValues as parameters
    }

Apex

   @AuraEnabled
   public static void handleUpdate(List<Enrollment__c> updateList){
   update updateList;
 }

the reason of page refreshing is because recordEditForm has own functionality of save and data table has own, so both can not work at same time.

or here if you are updating only one record then you can go for recordEditForm without data table , here is an example :

<lightning-record-edit-form record-id={recordId} object-api-name="Enrollment__c"  >
 <lightning-input-field field-name="Name">
   //you can add more fields here
</lightning-record-edit-form>

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.