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
le quang anhle quang anh 

How to list horizontally pictures in LWC ?

I want to list the birthday of all users by using LWC but i just want to show their profile pictures which is set horizontally side by side. How can I do that?
Best Answer chosen by le quang anh
CharuDuttCharuDutt
HIi Le Quang Anh
Try Below Code
LWC
<template>
        <lightning-card title="My-Users" icon-name="custom:custom11">
           <lightning-layout multiple-rows="true">
              <lightning-layout-item class="slds-p-around_xx-small" size="12">
                 <lightning-layout>
                    <lightning-layout-item class="slds-p-around_xx-small" size='12'>
                       <div>
                          <lightning-layout class='casedt'>
                             <template for:each={data} for:item="item">
                                <lightning-layout-item size="3" class="slds-m-around_x-small slds-border_top slds-border_left slds-border_bottom slds-border_right" key={item.id} >
                                   <lightning-tile label='' type="media" variant="Narrow">
                                      <div class='imgBox'>
                                         <img class='slds-m-top_small' src={item.FullPhotoUrl} height='200px' width='200px'></img>
                                      </div>
                                      <br>
                                      <p class='slds-m-bottom_small' ><b>User Name: </b><a href={recordPageUrl} data-item={item.Id} >{item.Name}</a></p>
                                   </lightning-tile>
                                </lightning-layout-item>
                             </template>
                          </lightning-layout>
                       </div>
                    </lightning-layout-item>
                 </lightning-layout>
              </lightning-layout-item>
           </lightning-layout>
        </lightning-card>
</template>
----------------------------------------

JS
import { LightningElement,wire,track,api } from 'lwc';
import getRecords from '@salesforce/apex/Users.getRecords';
export default class TestingComponent extends LightningElement {
    @track data = [];
    error;
    recordId;
    recordPageUrl;
    wiredActivities;
    
      @wire(getRecords)
    wiredclass(value){
      this.wiredActivities = value;
      const { data, error } = value;
      if (data) { 
        let lstdata = JSON.parse(JSON.stringify(data));
          this.data = lstdata;
          this.error = undefined;  
      } else if (error) {  
          this.error = error; 
          this.data = undefined;  
      }  
    }
}
------------------------------------

CSS
.casedt{
    overflow-y: auto;
}
.imgBox{
    height: 200px;
    width: 200px; 
}
a{
    color: black;
}
.slds-m-around_x-small{
    border-radius: 4px;
}
.slds-box{
    margin-top: 100%;
}

--------------------------------
Apex
public class Users {
@AuraEnabled(cacheable = true)
    public static list<User> getRecords(){
        list<User> myrecords = [SELECT Id, Name, SmallPhotoUrl, FullPhotoUrl FROM User];
        system.debug('my====>'+myrecords);
     
        return myrecords;
    }
}
Please Mark It As Best Answer If It Helps
Thank You!

 

All Answers

CharuDuttCharuDutt
HIi Le Quang Anh
Try Below Code
LWC
<template>
        <lightning-card title="My-Users" icon-name="custom:custom11">
           <lightning-layout multiple-rows="true">
              <lightning-layout-item class="slds-p-around_xx-small" size="12">
                 <lightning-layout>
                    <lightning-layout-item class="slds-p-around_xx-small" size='12'>
                       <div>
                          <lightning-layout class='casedt'>
                             <template for:each={data} for:item="item">
                                <lightning-layout-item size="3" class="slds-m-around_x-small slds-border_top slds-border_left slds-border_bottom slds-border_right" key={item.id} >
                                   <lightning-tile label='' type="media" variant="Narrow">
                                      <div class='imgBox'>
                                         <img class='slds-m-top_small' src={item.FullPhotoUrl} height='200px' width='200px'></img>
                                      </div>
                                      <br>
                                      <p class='slds-m-bottom_small' ><b>User Name: </b><a href={recordPageUrl} data-item={item.Id} >{item.Name}</a></p>
                                   </lightning-tile>
                                </lightning-layout-item>
                             </template>
                          </lightning-layout>
                       </div>
                    </lightning-layout-item>
                 </lightning-layout>
              </lightning-layout-item>
           </lightning-layout>
        </lightning-card>
</template>
----------------------------------------

JS
import { LightningElement,wire,track,api } from 'lwc';
import getRecords from '@salesforce/apex/Users.getRecords';
export default class TestingComponent extends LightningElement {
    @track data = [];
    error;
    recordId;
    recordPageUrl;
    wiredActivities;
    
      @wire(getRecords)
    wiredclass(value){
      this.wiredActivities = value;
      const { data, error } = value;
      if (data) { 
        let lstdata = JSON.parse(JSON.stringify(data));
          this.data = lstdata;
          this.error = undefined;  
      } else if (error) {  
          this.error = error; 
          this.data = undefined;  
      }  
    }
}
------------------------------------

CSS
.casedt{
    overflow-y: auto;
}
.imgBox{
    height: 200px;
    width: 200px; 
}
a{
    color: black;
}
.slds-m-around_x-small{
    border-radius: 4px;
}
.slds-box{
    margin-top: 100%;
}

--------------------------------
Apex
public class Users {
@AuraEnabled(cacheable = true)
    public static list<User> getRecords(){
        list<User> myrecords = [SELECT Id, Name, SmallPhotoUrl, FullPhotoUrl FROM User];
        system.debug('my====>'+myrecords);
     
        return myrecords;
    }
}
Please Mark It As Best Answer If It Helps
Thank You!

 
This was selected as the best answer
le quang anhle quang anh
Hello CharuDutt, how can I  only filter this month users's birthday picture in the code?
CharuDuttCharuDutt
Hii Le Quang Anh
Try Below Apex 
SELECT Id, Name, SmallPhotoUrl, FullPhotoUrl FROM User Where CreatedDate = THIS_MONTH

----------------------------------------------------------
​​​​​​​public class Users { 
@AuraEnabled(cacheable = true)     
public static list<User> getRecords(){
   list<User> myrecords = [​​​​​​​SELECT Id, Name, SmallPhotoUrl, FullPhotoUrl FROM User Where CreatedDate = THIS_MONTH]   
system.debug('my====>'+myrecords);               
return myrecords;     
} 
}
Please Don't Forget To  Mark It As Best Answer If It Helps
Thank You!