You need to sign in to do that
Don't have an account?
Nitin 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 ?
I am new to Salesforce Lightning.Can anyone give me an example of Carousel implementation through Salesforce lightning ?
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
<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>
I have just shown how the carousal implementation happens in lightning 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
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}
@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 ....
I have given 3 links above, when u paste it in browser u get something like this shown below.
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
Here is how i have my componets set up
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
(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.