Does anyone here know how to clear the selected rows of lightning:datatable on a button click or post processing of checked records?


You need to get the index of the selected row and remove it from the data attribute, something like this:

getSelectedName: function (cmp, event) {
        var selectedRows = event.getParam('selectedRows');
        console.log('SelectedRows.. '+JSON.stringify(selectedRows));
        var arr = cmp.get('v.mydata');

        for (var i = 0; i < selectedRows.length; i++){
            console.log('You selected: ' + selectedRows[i].opportunityName);
            var indexOfStevie = arr.findIndex(j => j.id == selectedRows[i].id);
            console.log('>>>Indexxx.. '+JSON.stringify(arr.splice(indexOfStevie,1)));
  • You suggestion worked perfectly. Thank you very much – Vishant Nov 30 '17 at 15:08
  • Glad I could help you – salesforce Developer Nov 30 '17 at 17:19

The following worked for me:

<aura:attribute name="defaultRows" type="List" default="[]" description="reset selected rows..." />
<lightning:datatable ... selectedRows="{!v.defaultRows}" ... />

So I am setting an empty list attribute for the selectedRows parameter of the dataTable that gets reset everytime it is refreshed. If this is not reset, then on refresh, the onRowsSelection is automatically fired again for the previous selection.

  • better to explain why you think this is the best solution and explain what your code does. Thanks – glls May 28 '18 at 13:19

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.