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
Nitin kumar 64Nitin kumar 64 

Carousel Implementation through Salesforce Lightining

Hi All,

I am new to Salesforce Lightning.Can anyone give me an example of Carousel implementation through Salesforce lightning ? 
Rupal KumarRupal Kumar
hi Nitin kumar,
                See below link-
                 https://developer.salesforce.com/blogs/developer-relations/2015/06/creating-carousel-lightning-component.html
                 https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/

    Thanks
Rashi Krishna
Mirketa Software Pvt Ltd
http://mirketa.com/index.html
 
prithvi kumarprithvi kumar
<aura:component controller="displayImage" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
   <ltng:require styles="/resource/Slider/Slider/bootstrap.min.css"/>    
    <ltng:require scripts="/resource/Slider/Slider/jquery.min.js,
                           /resource/Slider/Slider/bootstrap.min.js"
   afterScriptsLoaded="{!c.myAction}"/>    
    
         <aura:handler name="init" action="{!c.myAction}" value="{!this}" />  
        <aura:attribute name="atlist" type="ImagesSlider__c"/>
        <aura:attribute name="recordId" type="Id"  />
        <aura:attribute name="recordIds" type="Id[]"  />
           <aura:attribute name="imagesUrl" type="String[]" />
        <aura:attribute name="interval" type="Integer" default="2000"/>   

    <div id="carousel-example-generic" class="carousel slide imageInterval" data-ride="carousel" >
       <aura:iteration items="{!v.atlist}" var="acc">    
        <ol class="carousel-indicators">
            <aura:iteration items="{!acc.Imagess__r}" var="imgUrl" indexVar="index">                                
                <aura:if isTrue="{!index == 0}">
                    <li data-target="#carousel-example-generic" data-slide-to="{!index}" class="active"></li>
                    <aura:set attribute="else">
                        <li data-target="#carousel-example-generic" data-slide-to="{!index}" ></li>
                    </aura:set>
                </aura:if>   
            </aura:iteration>      
        </ol>
         </aura:iteration>
        
        <div class="carousel-inner" role="listbox">  
             <aura:iteration items="{!v.atlist}" var="acc">    
            <aura:iteration items="{!acc.Imagess__r}" var="imgUrl" indexVar="index">   
                <aura:if isTrue="{!index == 0}">
                    <div class="item active" >
                        <ui:outputRichText value="{!imgUrl.UploadImage__c}" class="img-responsive"/>
                        <div class="carousel-caption"> </div>
                    </div>
                    <aura:set attribute="else" >
                        <div class="item " >
                            <ui:outputRichText value="{!imgUrl.UploadImage__c}"  class="img-responsive"/>
                            <div class="carousel-caption"> </div>
                        </div>
                    </aura:set>
                </aura:if>
                
            </aura:iteration>
                 </aura:iteration>
        </div>
    
        <a class="left carousel-control" href="" role="button" data-slide="prev" onclick="{!c.Previous}">
            <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
            <span class="sr-only">Previous</span>
        </a>
        <a class="right carousel-control" href="" role="button" data-slide="next" onclick="{!c.Next}">
            <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> 
            <span class="sr-only">Next</span>
        </a> 
    </div>
               
</aura:component>
Mitchell Woloschek 9Mitchell Woloschek 9
^ just the component code with no references to other portions of code that are used and no explanation. Nailed it
prithvi kumarprithvi kumar
Hey Mitch,
I have just shown how the carousal implementation happens in lightning component. 
prithvi kumarprithvi kumar
Here is the record specific carousal component

I have created two custom objects Named ImagesSlider__c and Imagess, where Imagess has lookup to ImagesSlider__c .
UploadImage__c is a rich text field in Imagess object where images are added for the carousal.

Controller:

public class displayImage {
 @AuraEnabled   
    public static list<ImagesSlider__c> Image(Id parentId){
        
       List<ImagesSlider__c> ImgUrlsList=new List<ImagesSlider__c>();
       for(ImagesSlider__c img : [SELECT id,name,(select name,UploadImage__c from Imagess__r)from ImagesSlider__c where id=:parentId]){            
            ImgUrlsList.add(img); 
        }
        system.debug('@@@@'+ImgUrlsList);
          return ImgUrlsList; 
           
    }
}

component:

<aura:component controller="displayImage" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
   <ltng:require styles="/resource/Slider/Slider/bootstrap.min.css"/>    
    <ltng:require scripts="/resource/Slider/Slider/jquery.min.js,
                           /resource/Slider/Slider/bootstrap.min.js"
   afterScriptsLoaded="{!c.myAction}"/>    
    
         <aura:handler name="init" action="{!c.myAction}" value="{!this}" />  
        <aura:attribute name="atlist" type="ImagesSlider__c"/>
        <aura:attribute name="recordId" type="Id"  />
        <aura:attribute name="recordIds" type="Id[]"  />
           <aura:attribute name="imagesUrl" type="String[]" />
        <aura:attribute name="interval" type="Integer" default="2000"/>   

    <div id="carousel-example-generic" class="carousel slide imageInterval" data-ride="carousel" >
       <aura:iteration items="{!v.atlist}" var="acc">    
        <ol class="carousel-indicators">
            <aura:iteration items="{!acc.Imagess__r}" var="imgUrl" indexVar="index">                                
                <aura:if isTrue="{!index == 0}">
                    <li data-target="#carousel-example-generic" data-slide-to="{!index}" class="active"></li>
                    <aura:set attribute="else">
                        <li data-target="#carousel-example-generic" data-slide-to="{!index}" ></li>
                    </aura:set>
                </aura:if>   
            </aura:iteration>      
        </ol>
         </aura:iteration>
        
        <div class="carousel-inner" role="listbox">  
             <aura:iteration items="{!v.atlist}" var="acc">    
            <aura:iteration items="{!acc.Imagess__r}" var="imgUrl" indexVar="index">   
                <aura:if isTrue="{!index == 0}">
                    <div class="item active" >
                        <ui:outputRichText value="{!imgUrl.UploadImage__c}" class="img-responsive"/>
                        <div class="carousel-caption"> </div>
                    </div>
                    <aura:set attribute="else" >
                        <div class="item " >
                            <ui:outputRichText value="{!imgUrl.UploadImage__c}"  class="img-responsive"/>
                            <div class="carousel-caption"> </div>
                        </div>
                    </aura:set>
                </aura:if>
                
            </aura:iteration>
                 </aura:iteration>
        </div>
    
        <a class="left carousel-control" href="" role="button" data-slide="prev" onclick="{!c.Previous}">
            <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
            <span class="sr-only">Previous</span>
        </a>
        <a class="right carousel-control" href="" role="button" data-slide="next" onclick="{!c.Next}">
            <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> 
            <span class="sr-only">Next</span>
        </a> 
    </div>
               
</aura:component>

Js:

({
     myAction : function(component, event, helper) {
          var speed=component.get("v.interval"); 
          var recordId = component.get("v.recordId");
        var oppt = component.get("c.Image");
        oppt.setParams({
            'parentId': recordId
        });
        oppt.setCallback(this, function(response){
            var state = response.getState();
            if(state === 'SUCCESS'){
                  var storeResponse = response.getReturnValue();            
                var count = 0;
                var i = 0;
                if (storeResponse == null) {
                    
                } else {
                    for (i = 0; i < storeResponse.length; i++) {
                        if (storeResponse[i].order < 0)
                            count++;
                    }                   
                    component.set("v.recordId", recordId);
                    component.set("v.atlist", storeResponse);
                    var ids = component.get("v.recordIds");
                    ids.push(recordId);
                    component.set("v.recordIds", ids);               
            }
            }
        });
        $A.enqueueAction(oppt);
          if(speed<500){
            alert("Min Interval 500 Millisecond");
        }else{
         /*   $('.carousel').carousel({
                interval: speed
            });
            $('.carousel').carousel({
                interval: true
            });  */
        }
    },
     Previous : function(component, event, helper) {
        $('#carousel-example-generic').carousel('prev'); 
    },
    Next : function(component, event, helper) {
        $('#carousel-example-generic').carousel('next'); 
        $('#carousel-example-generic').carousel(200);
        
    },

})

Thanks
prithvi kumar
 
Khylin EdwardsKhylin Edwards
@prithvi kumar I have put in place your code with no error however when I uploaded an image it doesn't show up in community app builder. The component shows up but not image any suggestion as to why?
Khylin EdwardsKhylin Edwards
@prithvi kumar here is the error message I am recieving 

This page has an error. You might just need to refresh it. Action failed: c:displayImage$controller$Next [$ is not a function] Failing descriptor: {c:displayImage$controller$Next}
prithvi kumarprithvi kumar
Hi,

@Khylin Edwards  " $ is not a function " error is because of ur jquery file is not uploaded in static resource (or) its not in proper order.

 <ltng:require styles="/resource/Slider/Slider/bootstrap.min.css"/>    
    <ltng:require scripts="/resource/Slider/Slider/jquery.min.js,
                           /resource/Slider/Slider/bootstrap.min.js"
   afterScriptsLoaded="{!c.myAction}"/>    


 Here in my static resource named Slider i have included these 3 files.

1. https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css
2. https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js
3.https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js

Note : Store the files in static resource folder(Slider in my case) with same order mentioned above.

Hope this should help u ....
 
Khylin EdwardsKhylin Edwards
@prithvi kumar Thank you so much for your reply. Me being a novice to this can you give me a little more direction on where I am suppose to store this information or how to use it. I am a little lost.
prithvi kumarprithvi kumar
Hi,

I have given 3 links above, when u paste it in browser u get something like this shown below.

User-added image

Now copy entire content from each link and store them in seperate files in desktop/local naming bootstrap.min.css, bootstrap.min.js, jquery.min.js.

put all of them in a folder and then zip it (I have named my folder as Slider). Finally add the zip file to salesforce via static resource

User-added image

 
Khylin EdwardsKhylin Edwards
@prithvi kumar Thank you again for the steps. I was able to create the static folder however I still don't get any images tp display now I get the error seen below via screenshot.
 User-added image

Here is how i have my componets set up
User-added image
Ankit Gupta SFDCLearnerAnkit Gupta SFDCLearner
Hi All,

If you are still facing the issue of JQuery or Bootstep than try below code. Only make a small change in the calling part of resources.

<ltng:require scripts="/resource/newSlider/jquery.min.js
                           ,/resource/newSlider/bootstrap.min.js" 
                  afterScriptsLoaded="{!c.myAction}"/>
    <ltng:require styles="/resource/bootstrapCss"/>


After using this it will work fine on lightning component.

only one issue will be remails which is not getting proprer "<", ">" symbols

for resolution of symbols follow

https://stackoverflow.com/questions/27555126/bootstrap-left-and-right-glyphicons-not-showing-in-carousel
https://stackoverflow.com/questions/31180782/left-and-right-arrows-not-appearning-in-carousel-in-bootstrap
https://stackoverflow.com/questions/29640263/bootstrap-glyphicon-icon-not-showing
https://teamtreehouse.com/community/bootstrap-glyphicon-not-displaying-question
Lakhan ThakurLakhan Thakur

(select name,UploadImage__c from Imagess__r)from ImagesSlider__c
                                 ^
ERROR at Row:1:Column:49
Didn't understand relationship 'Imagess__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.