carousel slider displays single item in Angular4 - html

Working in an Angular4 project in this ,I have used carousel for displaying products,Products are binding from API response .
In my carousel I display the products like single row 3 column format ,If API returns 10 products the 10 th product is get displayed single slide .
I want to merge the 10th product with 1st and 2nd product then display like a 3 column slide .
Html
<div class="col-sm-9">
<section class="container">
<div class="row">
<div class="col-sm-1">
<i class="fa fa-user" style="font-size:25px"></i>
</div>
<div class="col-sm-9">
<h5>Popular Products</h5>
</div>
</div>
</section>
<hr>
<section class="carousel slide" id="myCarousel">
<div class="container">
<div class="row">
<div class="col-sm-12 text-right mb-4">
<a class="btn btn-outline-secondary carousel-control left" href="#myCarousel" data-slide="prev" title="go back">
<i class="fa fa-lg fa-chevron-left"></i>
</a>
<a class="btn btn-outline-secondary carousel-control right" href="#myCarousel" data-slide="next" title="more">
<i class="fa fa-lg fa-chevron-right"></i>
</a>
</div>
</div>
</div>
<div class="container p-t-0 m-t-2 carousel-inner">
<div class="row row-equal carousel-item {{ i == 0 ? 'active' : '' }} m-t-0" *ngFor="let chunkProducts of productData;let i =index;">
<div class="col-sm-4" *ngFor="let slider of chunkProducts;">
<div class="card">
<div class="card-img-top card-img-top-250 one">
<img class="img-fluid" [src]="slider['PRODUCT_IMAGE']" alt="Carousel 1">
<img routerLink="/my-cart" class="img-fluid two" [src]="slider['PRODUCT_IMAGE_ONHOVER']" alt="Carousel 1">
</div>
<div class="card-block pt-2">
<div class="col-sm-12 text-center card-text">
<span>{{slider.PRODUCT_NAME}}</span>
<br>
<input type="hidden" value="{{slider.PRODUCT_ID}}" #Pname1>
<br>
<span>{{slider.PRODUCT_PRICE}}</span>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
This is my html file to show the slide as 3 column format.
Component
ngOnInit() {
this.CartdataService.get_New_Products().subscribe(
data => {
this.productData = this.chunks(data,3);
console.log(this.productData);
});
chunks(array, size) {
let results = [];
results = [];
while (array.length) {
results.push(array.splice(0, size));
}
return results;
}

Just Change :
this.CartdataService.get_New_Products().subscribe(data => {
this.productData = this.chunks(data.json(),3);
let last = this.productData[this.productData.length-1].length;
if(this.productData.length > 1 && last < 3) {
this.productData[this.productData.length-1] = [ ...this.productData[this.productData.length-1] , ...this.productData[0].slice(0, 3-last) ];
}
});
WORKING DEMO

Related

handle Onclick event from Vue to Vuex

I'm switching from vue to vuex and I'm having trouble implementing an onclick event. I'm using bootstrap collapse to create 3 div. Each div has a button to show the collapsible elements inside. With vue I'm taking the data from an api request. I want every single button to open its parent div. Currently every button open all the three divs. When using vue I simply wrote this:
methods:{
//set expand to true foreach player card,
//set open to true foreach plus button
playerCardCollapse(index) {
this.teams = this.teams.map((item, i) => {
item.expanded = !item.expanded
item.open = !item.open
if (i !== index) {
item.expanded = false
item.open = false
}
return item
})
},
},
This is my template:
<!-- Container Card -->
<div v-for="(team, i) in teams" :key="i" class="col-6">
<div class="row mb-2 team-default align-items-center" style="height:106px;">
<div class="col-2 section">
<img class="rounded-circle" :src="team.team_img" style="border:2px solid #fff;box-shadow: 0 2px 31px 0 rgba(0, 0, 0, 0.23);">
</div>
<div class="col section team end">
<p class="intestazione">Team Name:</p>
<p class="result">{{team.team_name}}</p>
</div>
<div class="col-2 section end">
<button type="button" class="btnProfile" data-bs-toggle="collapse" data-bs-target="#profile-row" :aria-expanded="team.expanded" aria-controls="profile-row" #click.prevent="playerCardCollapse(i)">
<div class="plus-icon" :class="{open: team.open}"></div>
</button>
</div>
</div>
<!-- Collapsed -->
<div v-if="team.player.length>0">
<div class="collapse show" :class="{show: team.expanded}">
<div v-for="(p, j) in team.player" :key="j" class="row team-default mt-2 mb-3" id="profile-row">
<div class="col-2 section">
<div class="player-img-container">
<img class="rounded-circle player-img" :src="p.profilePic">
<img class="rounded-circle flag-img" src="https://picsum.photos/31/31">
</div>
</div>
<div class="col section team end">
<p class="intestazione">Team {{p.role}}</p>
<p class="result">{{p.name}}</p>
</div>
<div class="col-4 section end">
<button class="btnProfile-cta">Visualizza Profilo</button>
</div>
</div>
</div>
</div>
</div>
But with vuex I don't know how to implement this playerCardCollapse().
Hope someone could help (I don't know if you need more code snippets)

How do I make the images show the same height? bootstrap 4

it shows up like that because my photo is not the same size, is there a solution for this problem?
enter image description here
here is the code:
<div class="features_items"><!--features_items-->
<h2 class="title text-center">Features Items</h2>
#foreach($products as $product)
<div class="col-sm-4 h-100">
<div class="product-image-wrapper ">
<div class="single-products h-100">
<div class="productinfo h-100 text-center">
<img src="{{$baseUrl . $product->feature_image_path}}" alt="" />
<h2>{{ number_format($product->price )}} VNĐ</h2>
<p>{{ $product->name }}</p>
<a href="#"
data-url="{{route('addToCart',['id'=> $product->id])}}"
class="btn btn-default add_to_cart">
<i class="fa fa-shopping-cart"></i>
Add to cart
</a>
</div>
<div class="product-overlay">
<div class="overlay-content">
<h2>{{ number_format($product->price )}} VNĐ</h2>
<p>{{ $product->name }}</p>
<button
data-url="{{route('addToCart',$product->id)}}"
class="btn btn-default add_to_cart"><i class="fa fa-shopping-cart"></i>Add to cart</button>
</div>
</div>
</div>
</div>
</div>
#endforeach
</div><!--features_items-->

MVC Print Page break not working, contents are cut off

I tried below code to break the page while printing however its not working, I learnt that the Page break won't work in nested div tags, I 'm not sure how to achieve this, basically I 'm trying to display images, so in a row there will be 4 or more than that based on the display size of screen however at the time of printing it should print 4 images in a row and the next 4 images should be printed in next page as if now while printing, the images and the contents are getting cut off, please help
<div class='row small'>
#foreach (var item in Model.BuyerList.ImageList)
{
<div class="card bg-light mb-3 mr-1 card-text-fixed-width" style='page-break-after:always'>
<div class="img-control">
#if (!string.IsNullOrWhiteSpace(item.ImageUrl))
{
<img src="#item.ImageUrl" style="height:150px;" class="card-img-top" alt="Card image" />
}
else
{
<img src="~/AdTrack Images/NoProductImage.png" style="height:150px;" class="card-img-top" alt="Card image" />
}
<div class="edit d-print-none">
<a data-toggle="modal"
data-id='{"id": "#item.Items.Number","ItemId":"#item.Items.ItemId", "AdId":"#item.Header.Id"}'
class="open-AddBookDialog btn btn-primary" href="#"><i class="fa fa-pencil fa-lg"></i></a>
</div>
<div class="delete d-print-none">
<a data-toggle="modal" data-id='{"id": "#item.Items.Number","ItemId":"#item.Items.Id", "AdId":"#item.Id"}'
class="open-delete btn btn-primary" href="#">
<i class="fa fa-trash" style="font-size:15px;color:red" id="delete" name="delete"></i>
</a>
</div>
<div class="edit d-print-none">
<a data-toggle="modal"
data-id='{"id": "#item.Items.Number","ItemId":"#item.Items.ItemId", "AdId":"#item.Header.Id"}'
class="open-AddBookDialog btn btn-primary" href="#"><i class="fa fa-info-circle fa-lg"></i></a>
</div>
}
</div>
<div class="card-header">
<div class="font-weight-bold">Page #Html.DisplayFor(modelItem => item.Number)- #Html.DisplayFor(modelItem => item.Business)</div>
<div class="row mb-2 font-weight-bold">
<div class="col-md-6">Cut: #Html.DisplayFor(modelItem => item.Items.Number)</div>
<div class="col-md-6 text-right">9-Box: #Html.DisplayFor(modelItem => item.Items.BoxNumber)</div>
</div>
<div class="row mb-2 font-weight-bold">
<div class="col-md-4">Group #Html.DisplayFor(modelItem => item.Department.Test)</div>
#*<div class="col-md-4">Div: #Html.DisplayFor(modelItem => item.Department.Division)</div>*#
<div class="col-md-4">Buyer #Html.DisplayFor(modelItem => item.Department.Test)</div>
<div class="col-md-4">Dept #Html.DisplayFor(modelItem => item.Items.Department)</div>
</div>
</div>
</div>
}
</div>
Add wrap div with style='page-break-after:always'.
<div class='row small'>
#foreach (var item in Model.BuyerList.ImageList)
{
<div style='page-break-after:always'>
<div class="card bg-light mb-3 mr-1 card-text-fixed-width" >
<div class="img-control">
#if (!string.IsNullOrWhiteSpace(item.ImageUrl))
{
<img src="#item.ImageUrl" style="height:150px;" class="card-img-top" alt="Card image" />
}
else
{
<img src="~/AdTrack Images/NoProductImage.png" style="height:150px;" class="card-img-top" alt="Card image" />
}
<div class="edit d-print-none">
<a data-toggle="modal"
data-id='{"id": "#item.Items.Number","ItemId":"#item.Items.ItemId", "AdId":"#item.Header.Id"}'
class="open-AddBookDialog btn btn-primary" href="#"><i class="fa fa-pencil fa-lg"></i></a>
</div>
<div class="delete d-print-none">
<a data-toggle="modal" data-id='{"id": "#item.Items.Number","ItemId":"#item.Items.Id", "AdId":"#item.Id"}'
class="open-delete btn btn-primary" href="#">
<i class="fa fa-trash" style="font-size:15px;color:red" id="delete" name="delete"></i>
</a>
</div>
<div class="edit d-print-none">
<a data-toggle="modal"
data-id='{"id": "#item.Items.Number","ItemId":"#item.Items.ItemId", "AdId":"#item.Header.Id"}'
class="open-AddBookDialog btn btn-primary" href="#"><i class="fa fa-info-circle fa-lg"></i></a>
</div>
}
</div>
<div class="card-header">
<div class="font-weight-bold">Page #Html.DisplayFor(modelItem => item.Number)- #Html.DisplayFor(modelItem => item.Business)</div>
<div class="row mb-2 font-weight-bold">
<div class="col-md-6">Cut: #Html.DisplayFor(modelItem => item.Items.Number)</div>
<div class="col-md-6 text-right">9-Box: #Html.DisplayFor(modelItem => item.Items.BoxNumber)</div>
</div>
<div class="row mb-2 font-weight-bold">
<div class="col-md-4">Group #Html.DisplayFor(modelItem => item.Department.Test)</div>
#*<div class="col-md-4">Div: #Html.DisplayFor(modelItem => item.Department.Division)</div>*#
<div class="col-md-4">Buyer #Html.DisplayFor(modelItem => item.Department.Test)</div>
<div class="col-md-4">Dept #Html.DisplayFor(modelItem => item.Items.Department)</div>
</div>
</div>
</div>
</div>
}
</div>
I had a similar problem, but I achieved it using CSS. Simply add a css class and give it width in percentage. For example, 30% if you want to display 3 pictures or 19% if you want to display 4 and you can also set margin accordingly if you want spaces between the images. In this way, the images would resize themselves accordingly no matter what screen size is.
Example:
img {
width: 30%;
float: left;
margin: 1.66%;
}
Please refer to this code pen link also: https://codepen.io/alinaalam/pen/YeLqWm

Dynamically loaded slider using bootstrap

I have the following design for a carousel slider
The first slide has a larger main image (and 4 smaller)
The second slide is split between 8 smaller images
The screenshots attached were built using bootstrap - something like this
<div class="item active">
<div class="col-xs-6 grid-col">
<img src="~/img01">
</div>
<div class="col-xs-3 grid-col">
<img src="~/img02">
<img src="~/img03">
</div>
<div class="col-xs-3 grid-col">
<img src="~/img04">
<img src="~/img05">
</div>
</div>
<div class="item">
<div class="col-xs-3 grid-col">
<img src="~/img06">
<img src="~/img07">
</div>
<div class="col-xs-3 grid-col">
<img src="~/img08">
<img src="~/img09">
</div>
<div class="col-xs-3 grid-col">
<img src="~/img01">
<img src="~/img02">
</div>
<div class="col-xs-3 grid-col">
<img src="~/img03">
<img src="~/img04">
</div>
</div>
Of course that was easy! Now I need to dynamically load my images it's got a lot more complicated.....
This is how my razor markup looks currently
<div class="listing-slider-grid">
<div class="row grid-row" id="listingSlider">
<div id="carouselListingSlider" class="carousel slide" data-ride="carousel" data-interval="4000">
<div class="carousel-inner" data-toggle="modal" data-target=".carousel-modal">
#foreach (var slide in Model.ListingSliderImages.ToArray().Split(8))
{
<div class="item #(firstItemInSlider ? "active" : "")">
#foreach (var row in slide.ToArray().Split(4))
{
<div class="row">
#foreach (var item in row)
{
<div class="col-xs-3">
<img class="small-slider-img" src="~/images/optimisedImages/testing-slider-images/#item.ImageDefinition.Url">
</div>
}
</div>
}
</div>
firstItemInSlider = false;
}
</div>
<a class="left carousel-control" href="#carouselListingSlider" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carouselListingSlider" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
</div>
</div>
And on screen the two slides are looking like this
not too bad but I haven't managed to get that larger image in (and I have issues on slider two when there aren't enough images to populate a full slide).
I'm really stumped with how to get that first large image when rendering a list using the Bootstrap grid system (I've been using this helpful article https://www.jerriepelser.com/blog/approaches-when-rendering-list-using-bootstrap-grid-system/)
Does anyone have any better ideas?
Thanks, Sam
You should make exception in the loop to set more width (xs-6) for that element:
<div class="row">
#foreach (var item in row)
{
if([Your condition]) {
<div class="col-xs-6">
<img class="small-slider-img" src="~/images/optimisedImages/testing-slider-images/#item.ImageDefinition.Url">
</div>
} else { // Current behavior
<div class="col-xs-3">
<img class="small-slider-img" src="~/images/optimisedImages/testing-slider-images/#item.ImageDefinition.Url">
</div>
}
}
</div>
If you add an xs-6 you have to modify the rest of the row, so all of them never exceed 12 value (maximum columns per row)

View more button inside a foreach loop only working for first item

I am looping through items on a foreach loop and every item comes with a "view more" tag. When I click it it should collapse and show more information about that item. My problem is that it is only collapsing for the first item on the loop. How do I make it work for every item that is returned?
#{
foreach (var news in Model)
{
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="single-item wow fadeInUp animated animated animated animated">
<div class="img-box">
<div class="img-holder">
<figure><img src="#news.file.Url" alt=""></figure>
</div>
</div>
<div class="news-content">
<h4>#news.Header</h4>
<div class="collapse" id="collapseExample">
#news.Description
</div>
<div class="show-more">
<a data-toggle="collapse" href="#collapseExample" data-parent="collapseExample" aria-expanded="true" aria-controls="collapseExample">Read More</a>
</div>
</div>
</div>
</div>
}
}
This is my loop
It's because you are rendering multiples elements with the same ID
Try this
var index = 1;
foreach(var news in Model){
[...]
<div class="collapse" id="collapse_#index">
#news.Description
</div>
<div class="show-more">
<a data-toggle="collapse" href="#collapse_#index" data-parent="collapseExample" aria-expanded="false" aria-controls="collapse_#index">Read More</a>
</div>
index++;
[...]
}
This way it will never repeat an ID element