# Show Save and Cancel buttons always on lightning datatable

I have a situation where I need to show Save and Cancel buttons on lightning datatable (inline edit) always. However, unless I edit some field the Save button will not appear. I am displaying the records which are not created yet and letting User to change the values. If the User does not want to change he may just check the checkbox and should be able to Save. But the button does not appear. I could not find anything in the documentation. Is there any way to achieve this?

Here is the lightning datatable I am using.

        <lightning:card title="New Recs">
<lightning:datatable
aura:id="newRecsDataTable"
columns="{! v.columns }"
data="{! v.dataNew }"
keyField="Id"
errors="{! v.errors }"
draftValues="{! v.draftValues }"
onsave ="{!c.onSave}"
selectedRows="{! v.selectedRecords }"
onrowaction="{! c.handleRowAction }" />
</lightning:card>   </aura:if>

component.set('v.columns', [
{label: 'Name', fieldName: 'Milestone_Name__c', editable:'false', type: 'text'},
{label: 'Status', fieldName: 'Status__c', editable:'true', type: 'picklist'},
{label: 'Start Date', fieldName: 'Start_Date__c', editable:'true', type: 'date'},
{label: 'Close Date', fieldName: 'Close_Date__c', editable:'true', type: 'date'}
]);

• What have you tried so far? Please update Your question with those details. – sanket kumar Nov 4 '18 at 17:34
• Shared it. If User just selects the checkbox and does not edit any values then he should be able to Save it as I am processing only the selected rows behind the scenes. @sanketkumar – Kanikala Nov 4 '18 at 17:44

Interesting question. I tried changing one of the values in the table programmatically, but that didn't do anything.

When a field is edited manually, an Aura event named getActivePanel is fired. I tried firing that manually, but that also didn't work.

The only other option I can think of is to set the DataTable's hideCheckboxColumn attribute to true. Use a wrapper class to add a checkbox column to the record data instead. When the checkbox is selected, that should register as a change, and cause the cancel & save buttons to display. Then, use your onsubmit handler to process the rows as needed.

• I have not tried this as I sticked to html table. But this solution seems to work for me. Thank you! @Shane – Kanikala Nov 6 '18 at 19:20

Better solution is to set draftValues when you load the table. You can set all the rows in the table as the draftValues or you can specify individual records. Either way, the table will appear as if it has already been edited and the Save/Cancel buttons will appear.

component.set("v.draftValues", component.get("v.dataNew "));

component.set("v.draftValues", [{}] );