function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sumit dsumit d 

After click on checkbox in data table a check box field should become true

Hi All,
i have a lightning component in which i am taking records of a custom object .here when i click on checkbox the record is removed.
but after reloading the page its coming again in data table i want that in this records  i have a Checkbox field (False_Positive__c). this field become true for the record. so that the record does not show again on data table.
how to do it?
Any suggestions?
my component and controller is given below:-
<aura:component controller="FBGFamilyController"
                implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" 
                access="global" >
    
    <!--aura:attribute name="PageHeading" type="String" default="Remove  False positive On Click Of Check Box" /-->
    <aura:attribute name="mydata" type="Object"/>
    <aura:attribute name="mycolumns" type="List"/>
    <aura:handler name="init" value="{!this}" action="{!c.doinit}" />
    
    
    <div class="slds-section slds-is-open">
        <h3 class="slds-section__title slds-theme_shade">
            <span class="slds-truncate slds-p-horizontal_small" title="Section Title">Family Records</span>
            <lightning:layoutItem class="right-align">
                <lightning:button label="New" onclick="{!c.createRecord}" class="buttonStyle"/>
            </lightning:layoutItem> 
        </h3>
        <lightning:datatable data="{! v.mydata }" 
                             columns="{! v.mycolumns }" 
                             keyField="Id" 
                             onrowselection="{! c.removeRow }"
                             hideCheckboxColumn="false"
                             />
        
    </div>
</aura:component>
Controller is given below:-
({
    doinit : function(component, event, helper) {
        component.set('v.mycolumns', [
            
            {label: 'Name', fieldName: 'linkName', type: 'url', 
             typeAttributes: {label: { fieldName: 'Name' }, target: '_blank'}},
            /*{label: 'Sister Account ', fieldName: 's1', type: 'url', 
             typeAttributes: {label: { fieldName: 'Sister_Company__r.Name' }, target: '_blank'}},
            {label: 'Sister Account ', fieldName: 's2', type: 'url', 
             typeAttributes: {label: { fieldName: ' Sister_Company2__r.Name' }, target: '_blank'}}*/
            {label: 'Division', fieldName: 'd1', type: 'text'},
            {label: 'Sister Account', fieldName: 's1', type: 'text'},
            {label: 'Sister Account', fieldName: 's2', type: 'text'},
            {label: 'State', fieldName: 'State__c', type: 'text'},
            {label: 'Type', fieldName: 'Type__c', type: 'text'},
            {label: 'Owner', fieldName: 'Oid', type: 'text'}
        ]);
        
        var action = component.get('c.fetchRecords');
        var recordId =  component.get("v.recordId");
        action.setParams({rid : recordId});
        action.setCallback(this, function(response){
            var state = response.getState();
            if(state === "SUCCESS"){
                var allValues = response.getReturnValue();
                
                for (var i = 0; i < allValues.length; i++) {
                    var row = allValues[i];
                    row.s1 = row.Sister_Company__r.Name;
                }
                for (var i = 0; i < allValues.length; i++) {
                    var row = allValues[i];
                    row.s2 = row.Sister_Company2__r.Name;
                }
                 for (var i = 0; i < allValues.length; i++) {
                    var row = allValues[i];
                    row.d1 = row.Sister_Company__r.RecordType.Name;
                }
                for (var i = 0; i < allValues.length; i++) {
                    var row = allValues[i];
                    row.Oid = row.Owner.Name;
                }
                 
                allValues.forEach(function(record){
                    record.linkName = '/'+record.Id;
                });
                /* allValues.forEach(function(record){
                     record.s1 = '/'+record.Sister_Company__r.Id;
                }); 
                 allValues.forEach(function(record){
                    record.s2 = '/'+record.Sister_Company2__r.Id;
                }); */
                console.log("allValues--->>> " + allValues);
                component.set('v.mydata', allValues);
            }
            else if(state === "ERROR") {
                var errors = response.getError();
                if(errors){
                    if(errors[0] && errors[0].message){
                        console.log("Error Message: " + errors[0].message);
                    }
                }
                else{
                    console.log("Unknown Error");
                }
            }
        });
        $A.enqueueAction(action);
    },
    
    removeRow : function(component, event, helper){
        var selRows = event.getParam('selectedRows');
        
        // Remove the record from the table
        var rows = component.get('v.mydata');
        for (var i = 0; i<selRows.length; i++){    
            var rowIndex = rows.indexOf(selRows[i]);
            console.log('rowIndex---->>> ' + rowIndex);
            var r=rows.splice(rowIndex, 1);   
            
            console.log('rrr---->>> ' + JSON.stringify(r));
            component.set('v.mydata', rows);
        }
    },
    
     createRecord : function (component, event, helper) {
        var createRecordEvent = $A.get("e.force:createRecord");
        createRecordEvent.setParams({
            "entityApiName": "FBG_Family__c"
        });
        createRecordEvent.fire();
    }
    
})
my Apex class is given below:-
public class FBGFamilyController {
        @AuraEnabled
    public static List<FBG_Family__c> fetchRecords(String rid) {
        return [SELECT Id, Name, Owner.Name,Type__c, Sister_Company__r.RecordType.Name, False_Positive__c,
                State__c, Division1__c, Sister_Company__r.Name, Sister_Company2__r.Name 
                FROM FBG_Family__c
                WHERE Sister_Company__c =: rid 
                AND False_Positive__c = FALSE
                ORDER BY Name  ASC ];
    }
}
i want when i click on Checkbox on data table a CheckBox field become False_Positive__c become true for that record.
how to do it?
Any suggestions?
Naveen KNNaveen KN
on record selection, you are calling this method removeRow and doing some operation in that. In the same method, you have to pass Id and field value to Apex method [create a new method for this] and write a logic to update that checkbox column for that record. 

- Naveen K N