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
Mounica M 10Mounica M 10 

how to redirect to the detail record page when you click a button on a lightning component

how to redirect to the detail record page when you click a button on a lightning component
I have calendar component(component-1) . when ever we click on a date, it pops a table with list of recordspresent in a day(component 2).now when we select a record by checking the check box beside it and click submit button it should be redirected to the record detail page.
Note: all the above is being implemented in a community built for the internal users.
<aura:component controller="EventDataTableServerCtrl" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" >
    <aura:attribute name="StartTest" type="Date"/>
    <aura:attribute name="StartDate" type="string" default="0"/>
    <aura:attribute name="EndDate" type="String" default="2018-01-02T12:00:00-05:00"/>
    <aura:attribute name="mydata" type="Object"/>
    <aura:attribute name="mycolumns" type="List"/>
    <aura:attribute name="SelectedRecord" type="String[]" default="0"/> 
    <!-- <aura:attribute name="isOpen" type="boolean" default="false"/> -->
    <aura:handler name="change" value="{!v.StartTest}" action="{!c.handleValueChange}"/>
    <aura:handler name="init" value="{! this }" action="{! c.init }"/>
       <div style="height: 300px;">
        <lightning:datatable data="{! v.mydata }" 
        columns="{! v.mycolumns }" 
       <lightning:button variant="brand" label="Submit" onclick="{! c.closeModel }" /> 

    init: function (cmp, event, helper) {
        //console.log(new Date(cmp.get('v.StartDate')).getMilliseconds());
        cmp.set('v.mycolumns', [
            {label: 'Event Name', fieldName: 'Name', type: 'text'},
            {label: 'Start Date & Time', fieldName: 'Event_Start_date_and_time__c', type: 'Date/Time'},
            {label: 'End Date & Time', fieldName: 'Event_End_Date__c', type: 'Date/Time'}
    handleValueChange : function (component, event, helper) {
         component.set('v.mycolumns', [
            {label: 'Event Name', fieldName: 'Name', type: 'text'},
            {label: 'Start Date & Time', fieldName: 'Event_Start_date_and_time__c', type: 'Date/Time'},
            {label: 'End Date & Time', fieldName: 'Event_End_Date__c', type: 'Date/Time'}
        // handle value change
        var date = event.getParam("value");
        console.log("old value: " + event.getParam("oldValue"));

        console.log("current value: " + event.getParam("value"));

    getSelectedName: function (cmp, event) {
        var selectedRows = event.getParam('selectedRows');
        for (var i = 0; i < selectedRows.length; i++){
      gotoURL : function (cmp, event, helper) {
    var eventId = cmp.get('v.SelectedRecord');
    var navEvt = $A.get("e.force:navigateToSObject");
      "recordId": eventId,
})User-added image
Mounica M 10Mounica M 10
right now we are working on  single event selection 
Seems like force:navigateToURL and force:navigateToSObject events only works in Salesforce1 app only.
Lightning datatable onrowselection, will call the method defined on checkbox selection. (So, you can skip submit button).
<lightning:datatable data="{!v.accountlist}" columns="{!v.mycolumns}" keyField="id" onrowselection="{!c.getDetail}" />
And in the getDetail function in controller :
Create a string which contain your domain base URL.
Get the record id of selected record.
getDetail : function(component, event, helper) {
    var selectedRows  = event.getParam('selectedRows');
    var firstId = selectedRows[0].Id;
// you can specify the base url
    var redUrl ="";;
Append both of them to get full URL.
Use javascript to redirect to Lightning record page.

Hope this helps.