In my workaround, I need to hide the cancel and save button of the datatable, this can be done by set the suppressBottomBar
to true. But I also need to leave the inline edit function avaliable, so I need to retrieve the draft values manually.
By clicking the default "Save" button, I can get the draft values by "event.getParam('deaftValues')
",
but in this case, there is no such event with the Param.
I've tried
component.find('datatableAuraId').get("v.draftValues")
/ component.get('datatableAuraId').draftValues
but failed.
Have any idea?
addtion:
I console.log(component.find('datatableAuraId').get("v.draftValues"))
and in my console I got []
as a result.
the step is
- click the pencil icon to active the edit cell mode
- make some edition
- click the test button, to see if the console log get any data.
- I got '[]' as the result.
addition2: I get the draftValues, it seems that although I edit the line data, the edit data will not set the draftValues in sync, it will always be [].
CMP:
<lightning:button label="test" onclick="{!c.testclick}" />
<lightning:datatable aura:id="calendarDataTable" data="{! v.orderCalendar }"
columns="{! v.Columns }" keyField="Id" draftValues="{! v.DraftValues }"
hideCheckboxColumn="false" onsave="{! c.handleSaveEdition }"
onrowselection="{!c.rowselection}" columnWidthsMode="fixed"
title="testTitile"/>
JS:
testclick: function(component, event, helper) {
console.log("console");
console.log(JSON.stringify(component.find('calendarDataTable').get('v.draftValues')));
console.log(JSON.stringify(component.get('v.DraftValues')));
},
When I make some inline changes and click test button, the logs are always '[]'
component.find('datatableAuraId').get("v.draftValues")
does work can you check if you are using the correct aura id of datatable? When you 'failed', are you getting any error? – rahul gawale Jul 16 '20 at 4:01