How to change column count in listing page Magento2? - magento2

I want to make product listing page to use 3 columns instead of 4 default columns.
I've got some categories on my Magento2 Web, and some products on each category. I want them to show as 3 columns count, but it always shows as 4 default columns count, how can i change plz help me for this.

Magento 2 don't have an option to set a column count as Magento 1.
To change from 4 to 3 (for theme based on Luma) you will need to change CSS and to reset image size.
CSS code that you need to change is inside Magento_Catalog module, file:
_listings.less
and it is like this:
.media-width(#extremum, #break) when (#extremum = 'min') and (#break = #screen__l) {
.products-grid .product-item { width: 100%/5 }
.page-layout-1column .products-grid .product-item { width: 100%/6 }
.page-layout-3columns .products-grid .product-item { width: 100%/4 }
.page-products .products-grid .product-items { margin: 0; }
.page-products .products-grid .product-item {
width: 24.439%;
margin-left: calc(~"(100% - 4 * 32.439%) / 3");
padding: 0;
&:nth-child(3n+1) {
margin-left: 0;
}
}
.page-products.page-layout-1column .products-grid .product-item { width: 100%/5 }
.page-products.page-layout-3columns .products-grid .product-item { width: 100%/4 }
}
to have 3 columns, change it to (I recommend add this code to _theme.less):
.media-width(#extremum, #break) when (#extremum = 'min') and (#break = #screen__l) {
.products-grid .product-item { width: 100%/4 }
.page-layout-1column .products-grid .product-item { width: 100%/5 }
.page-layout-3columns .products-grid .product-item { width: 100%/3 }
.page-products .products-grid .product-items { margin: 0; }
.page-products .products-grid .product-item {
width: 32.439%;
margin-left: calc(~"(100% - 3 * 32.439%) / 2");
padding: 0;
&:nth-child(3n+1) {
margin-left: 0;
}
}
.page-products.page-layout-1column .products-grid .product-item { width: 100%/4 }
.page-products.page-layout-3columns .products-grid .product-item { width: 100%/3 }
}
after this in
/your_theme/etc/view.xml
change small image width and height. Now is 240 and 300, change it to something like 300 and 330.
Refresh and that is it.

Related

How can I use #property in #emotion/styled?

Hello I want to customize my css property using the below method (#property).
https://css-tricks.com/using-property-for-css-custom-properties/
How can I use in emotion?
I want to use this inside code below.
export const Typography = styled("h4", {
label: "Typography"
})<{}>(() => {
return {
fontSize: 36,
fontWeight: 400,
marginBottom: 40,
color: palette.grey.default,
width: 300,
letterSpacing: -1
};
});
And make increasing number animation like below.
#property --num1 {
syntax: "<integer>";
initial-value: 0;
inherits: false;
}
#property --num2 {
syntax: "<integer>";
initial-value: 0;
inherits: false;
}
#property --num3 {
syntax: "<integer>";
initial-value: 0;
inherits: false;
}
div {
counter-reset: num1 var(--num1) num2 var(--num2) num3 var(--num3);
font-size: 40px;
font-weight: bold;
animation: animate 2s forwards ease;
}
div:before {
content: counter(num1) counter(num2) counter(num3);
}
#keyframes animate {
to {
--num1: 3;
--num2: 8;
--num3: 999999;
}
}

QML Change Size of Dropitem on Drop

I want to change the size of a Rectangle in the QML drag and drop example on drop to the size of the drop area. But somehow the Rectangle will not render to the new size although it takes the width and height values.
DragTile.qml
import QtQuick 2.0
Item
{
id: rootItem
property int boxWidth: 0
property int boxHeight: 0
property Item dragParent
width: boxWidth
height: boxHeight
MouseArea
{
id: mouseArea
width: rootItem.boxWidth
height: rootItem.boxHeight
drag.target: msgTile
onReleased:
{
parent = msgTile.Drag.target !== null ? msgTile.Drag.target : rootItem
rootItem.boxHeight = parent.boxHeight
rootItem.boxWidth = parent.boxWidth
}
Rectangle
{
id: msgTile
color: "cyan"
width: mouseArea.width
height: mouseArea.height
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
Drag.active: mouseArea.drag.active
Drag.hotSpot.x: width / 2
Drag.hotSpot.y: height / 2
//draging
states: State
{
when: mouseArea.drag.active
ParentChange { target: msgTile; parent: dragParent } // draw on top while draging
AnchorChanges { target: msgTile; anchors.verticalCenter: undefined; anchors.horizontalCenter: undefined }
}
}
}
}
The dragsource as well as the droparea take the size of a parent rectangle
in Main.qml
Rectangle
{
x: 100
y: 100
width: 100
height: 300
border.width: 1
DragSource
{
msgCount: 2
msgCapacity: 10
dragParent: topItem
}
}
Rectangle
{
x: 400
y: 100
width: 150
height: 300
border.width: 1
MsgDrop
{
msgCapacity: 12
}
}
The size of the droparea is a little bit larger, than the size of the dragtiles
Is there any order of rendering that I am missing?
I would be very happy for some advice.
Best regards

IONIC [native-file, image-picker] does not work writeFile on iOS

There is such a method:
public loadGallery():void{
let options ={
maximumImagesCount: 20,
width: 500,
height: 500,
quality: 75
};
this.imagePicker.getPictures(options).then((result) => {
for (let i = 0; i < result.length; i++) {
this.imgList.push({'win':{id: result[i], title: result[i]}});
}
let builder = new xml2js.Builder();
let xml = builder.buildObject(this.imgList);
this.file.writeFile(this.file.dataDirectory,'mywins.xml', xml, {replace: true});
},
function(errmsg){
console.log('---->'+ errmsg)
});
}
On Android it works, on iOS it saves only at the first start, at the following only adds to the array when you shoot out the photo, but the file does not overwrite.

How to Properly Use +cache function in Stylus

I am trying to create a mixin using variables and the cache function. It works fine, except for one problem. See sample code below and then I'll explain the problem.
First, here is the mixin (simplified for reasons of space, but in essence this is how it works):
mixin($type = apples,
$color = blue,
$font-size = 12px,
$margin = 10px,
$padding = 20px,
$border-radius = 30px
)
if $type == apples
$color = red
if $type == oranges
// code
if $type == peas
// code
+cache('color' + $color)
color $color
+cache('font-size' + $font-size)
font-size $font-size
+cache('margin' + $margin)
margin: $margin
+cache('padding' + $padding)
padding: $padding
+cache('border-radius' + $border-radius)
border-radius: $border-radius
.one
mixin($font-size: 13px)
.two
mixin($type: oranges)
.three
mixin($type: peas)
This outputs the following code:
.one {
color: #f00;
}
.one {
font-size: 13px;
}
.one,
.two,
.three {
margin: 10px;
}
.one,
.two,
.three {
padding: 20px;
}
.one,
.two,
.three {
border-radius: 30px;
}
.two,
.three {
color: #00f;
}
.two,
.three {
font-size: 12px;
}
The problem with this method is that the selectors are being unnecessarily repeated. We could easily combine classes one, two and three together for margin, padding and border-radius and classes two and three together for color and font-size.
So let's try another tact for +cache:
+cache(
'color' + $color,
'font-size' + $font-size,
'margin' + $margin,
'padding' + $padding,
'border-radius' + $border-radius
)
color $color
font-size $font-size
margin: $margin
padding: $padding
border-radius: $border-radius
This outputs the following code:
.one {
color: #f00;
font-size: 13px;
margin: 10px;
padding: 20px;
border-radius: 30px;
}
.two,
.three {
color: #00f;
font-size: 12px;
margin: 10px;
padding: 20px;
border-radius: 30px;
}
Now we are unnecessarily outputting properties. margin, padding and border-radius are each mentioned twice.
What I want is a method that will produce the following result:
.one,
.two,
.three {
margin: 10px;
padding: 20px;
border-radius: 30px;
}
.one {
color: #f00;
font-size: 13px
}
.two,
color: #00f;
font-size: 12px;
}
Unfortunately, no. As it stands this is the best you will get with +cache. Although, to make things a bit more readable you can use +cache(arguments) like I have done bellow.
mixin($type = apples,
$color = blue,
$font-size = 12px,
$margin = 10px,
$padding = 20px,
$border-radius = 30px
)
+cache(arguments)
if $type == apples
$color = red
if $type == oranges
// code
if $type == peas
// code
color $color
font-size $font-size
margin: $margin
padding: $padding
border-radius: $border-radius
A CSS minifier should do what you want. For example, cssnano reduces your original, verbose CSS down to the following (I added whitespace for readability):
.one{
color:red;
font-size:13px
}
.one,.three,.two{
margin:10px;
padding:20px;
border-radius:30px
}
.three,.two{
color:#00f;
font-size:12px
}
Here is the code in action.

How to add EventListener for dynamic contents in iphone

I am developing iphone application in Titanium. Unable to set addEventListener to my dynamically receiving contents.
Here is my code:
var receivedAccountsLength = Ti.App.userAccounts.length;
var topFrom = 100;
for(var i=1;i<receivedAccountsLength;i++)
{
var cont = Ti.UI.createLabel({text: Ti.App.userAccounts[i].accountName , width: 100, height: 30, borderWidth: 1, top: topFrom });
win.add(cont);
cont.addEventListener('click', function()
{
alert("cont");
});
topFrom += 50;
}
can any one..
#suresh Try this code this is Absolute working for you.
first you get your "eventListener object" then you can get you its property,
for help just Copy paste this code
var receivedAccountsLength = Ti.App.userAccounts.length;
var topFrom = 100;
for(var i=1;i<receivedAccountsLength;i++)
{
var cont = Ti.UI.createLabel({text: Ti.App.userAccounts[i].accountName , width: 100, height: 30, borderWidth: 1, top: topFrom });
cont.addEventListener('click', function(event)
{
alert("cont : "+ event.source.text);
});
win.add(cont);
topFrom += 50;
}
If, working the enjoy Titanium .....Cheers...!