-
-
Save sumugapadman/b31488774df70e50c9f8bf64d3c9ac33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Accountcontroller { | |
@AuraEnabled | |
public static List<Account> getAccounts() { | |
return [Select Id, Name, Industry, Phone from Account limit 10]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:component controller="Accountcontroller" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" > | |
<aura:attribute name="mydata" type="List"/> | |
<aura:attribute name="mycolumns" type="List"/> | |
<aura:attribute name="selectedRows" type="List"/> | |
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/> | |
<lightning:datatable aura:id="mytbl" data="{!v.mydata}" | |
columns="{!v.mycolumns}" | |
keyField="Id" | |
selectedRows="{!v.selectedRows}" | |
onrowaction="{!c.handleAction}" | |
/> | |
</aura:component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
doInit : function(component, event, helper) { | |
component.set('v.mycolumns', [ | |
{label: 'Account Name', fieldName: 'Name', type: 'text'}, | |
{label: 'Phone', fieldName: 'Phone', type: 'phone'}, | |
{label: 'Industry', fieldName: 'Industry', type: 'text'} | |
]); | |
var action = component.get("c.getAccounts"); | |
action.setCallback(this, function(response) { | |
var state = response.getState(); | |
if (state === "SUCCESS") { | |
console.log(response.getReturnValue()); | |
component.set('v.mydata', response.getReturnValue()); | |
// trying to set the selected rows | |
var selected_rows = helper.getSomeRows(response.getReturnValue(), 3); | |
var selected_rows_mod = ["00161000002K6BbAAK", "00161000002K6BcAAK", "00161000002K6BdAAK"]; | |
component.set("v.selectedRows",selected_rows_mod); | |
} | |
}); | |
$A.enqueueAction(action); | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
getSomeRows : function(objs, cnt) { | |
var selected_records = []; | |
for(var i=0; i<cnt; i++){ | |
selected_records.push(objs[i].Id); | |
} | |
return selected_records; | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment