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

2 Answers 2


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
    Commented Nov 30, 2017 at 15:08
  • Glad I could help you Commented Nov 30, 2017 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
    Commented May 28, 2018 at 13:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .