I have somewhat similar requirement Search on LightningData Table The search part works for me butthe challenge that I am having is when I search for a row and select it, then search for another row , select a new row. The previously selected row gets deselected because I am using searchData to load everytime a search is instantiated. How can I make this work? Here is the Component:

 <aura:attribute name="repData" type="Object"/>
     <aura:attribute name="repColumns" type="List"/>
<aura:attribute name="selectedReport" type="Object"/>
 <!-- Search Attribute-->
     <aura:attribute name="searchText" type="String"/>
     <!--Search on full report list-->
     <aura:attribute name="searchData" type="Object"/>

 <!-- handlers-->
    <aura:handler name="init" value="{! this }" action="{! c.init }"/>
    <!-- Real time filtering based on changes to the filter text -->
    <aura:handler name="change" value="{!v.searchText}" action="{!c.updateFilter}" />

<div class="searchBar">
                        <lightning:input name="search" value="{!v.searchText}" label="Search" onchange="{!c.updateFilter}"/>

<lightning:datatable data="{! v.repData }"
                        columns="{! v.repColumns }"

repCOlumns and searchData both are set during the initial load. Below is the handleSearch: Controller:

// Apply filter to the list of all items
    updateFilter: function(component) {
        var data = component.get("v.searchData"),
            term = component.get("v.searchText"),
            //newdata = data.filter(item => (!term) || item.Name.toLowerCase().indexOf(term.toLowerCase()) > -1);
            newdata = data.filter(function(item) {
                console.log('Item' +item.Name);
                return (!term) || item.Name.toLowerCase().indexOf(term.toLowerCase()) > -1; 

        component.set("v.repData", newdata);
        console.log('Left column after search'+newdata);

put on hold as off-topic by glls, Reshma, Pranay Jaiswal, Raul, battery.cord 2 days ago

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on problems in code you've written must describe the specific problem and include valid code to reproduce it. For help writing short, self-contained syntactically-valid examples, see: SSCCE.org" – glls, Reshma, Pranay Jaiswal, Raul, battery.cord
If this question can be reworded to fit the rules in the help center, please edit the question.

  • What exactly do you want to achieve? that the second time you search it would be a new search? – Itai Shmida 2 days ago
  • What I am trying to achieve is when I search the second time, I would like the system to remember my first selected row, right now its not working. When I perform a second search, it forgets the first selected row. – P.Shri 2 days ago