How to Create Grid/Tile View

How to Create Grid/Tile View?

This type of layout is called Masonry layout. Masonry is another grid layout but it will fill out the whitespace caused by the difference height of elements.

jQuery Masonry is one of jQuery plugin to create masonry layout.

Alternatively, you can use CSS3 columns. But for now jQuery based plugin is the best choice since there is compatibility issue with CSS3 column.

Grid/Tile view with angularjs

Go for AngularJS Masonry. You can see the demo at the homepage. And using it is simple using a masonry-brick class:

<div masonry>
<div class="masonry-brick" ng-repeat="brick in bricks">
<img ng-src="{{ brick.src }}" alt="A masonry brick">
</div>
</div>

UPDATE

In order for your masonry-brick to not overlap with each other, you need to reload masonry whenever you show or hide an inner div. I've added a function to do so on ng-click which will also broadcast a masonry.reload event to reload the same.

Check this working code.

JS

$scope.showItem = function(index) {
$scope.items[index].show = !($scope.items[index].show);
$scope.$broadcast('masonry.reload');
}

HTML

<div masonry>
<div ng-repeat="item in items" class="masonry-brick item">
{{item.name}}
<button class="toggle-button" ng-click="showItem($index)">show</button>
<button class="toggle-button" ng-click="remove($index)">X</button>
<div ng-if="item.show" class="hidden-box">
This is a hidden box for {{$index+1}}th item.
</div>
</div>
</div>

EDIT

There seems to be a problem due to the fact that masonry reloads instantly while the animation of the masonry transition takes time. I've added some transition duration and $timeout in this plunk.

How can I make each grid tile clickable to bring me to a new page in Flutter

import 'package:flutter/material.dart';

class GridOne extends StatefulWidget {

@override
_GridOneState createState() => new _GridOneState();
}

class _GridOneState extends State<GridOne> {
@override
Widget build(BuildContext context) {
return new Scaffold(
body: GridView.count(
crossAxisCount: 6,
children: List.generate(
947,
(index) {
return RawMaterialButton(
onPressed: () {
/// Navigation code will come here
},
child: Card(
elevation: 10.0,
color: Color(0xFF184946),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
color: Color(0xFF184946),
child: Center(
child: Text(
'$index',
style: TextStyle(fontSize: 18, color: Color(0xFFFCF8F8)),
),
),
),
),
),
);
},
),
),
);
}

How to create GridView Layout in Flutter

A simple example loading images into the tiles.

import 'package:flutter/material.dart';

void main() {
runApp( MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(

color: Colors.white30,
child: GridView.count(
crossAxisCount: 4,
childAspectRatio: 1.0,
padding: const EdgeInsets.all(4.0),
mainAxisSpacing: 4.0,
crossAxisSpacing: 4.0,
children: <String>[
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
].map((String url) {
return GridTile(
child: Image.network(url, fit: BoxFit.cover));
}).toList()),
);
}
}

The Flutter Gallery app contains a real world example, which can be found here.

Sample Image

List / Grid / Tile view transitions using jquery or javascript

Here is my basic implementation. I've tried to create output like the video.
The idea is to wrap list item in a wrapper. Wrappers are statically placed and list items are absolutely placed. When view changes wrapper gets arranged automatically as per stylesheet or container rules. But move list items after with animations.

var pos = [];
var offs = null;

function init() {
offs = $(".container").first().offset();
$(".wrapper").each(function (i) {
updatePositions();
$(this).children(0).css({
top: pos[i].top,
left: pos[i].left
});
});
}

$(document).ready(function () {
init();
});

$(window).resize(function () {
init();
})

function updatePositions() {
$(".wrapper").each(function(index) {
var tp = $(this).offset().top - offs.top;
var lf = $(this).offset().left - offs.left;
pos[index] = {
top: tp,
left: lf
};
});
}

function grid() {
if ($(".wrapper").first().hasClass("gv-wrapper")) return;
updatePositions();
$(".wrapper").each(function(index) {
$(this).removeClass("dv-wrapper cv-wrapper");
$(this).addClass("gv-wrapper");

$(this).children(0).css({
opacity: 0.8,
top: pos[index].top,
left: pos[index].left
});
});

updatePositions();
$(".wrapper").each(function(index) {
$(this).children(0).children(0).removeClass("dv-video cv-video");
$(this).children(0).children(1).removeClass("dv-details cv-details");
$(this).children(0).children(0).first().addClass("gv-video");
$(this).children(0).children(1).last().addClass("gv-details");
$(this).children(0).animate({
height: "100px",
width: "200px",
opacity: 1,
top: pos[index].top,
left: pos[index].left
}, 1000, "swing");
});
}


function detailed() {
if ($(".wrapper").first().hasClass("dv-wrapper")) return;

updatePositions();

$(".wrapper").each(function(index) {
$(this).removeClass("gv-wrapper cv-wrapper");
$(this).addClass("dv-wrapper");

$(this).children(0).css({
opacity: 0.8,
top: pos[index].top,
left: pos[index].left
});
});

updatePositions();
$(".wrapper").each(function(index) {
$(this).children(0).children(0).removeClass("gv-video cv-video");
$(this).children(0).children(1).removeClass("gv-details cv-details");
$(this).children(0).children(0).first().addClass("dv-video");
$(this).children(0).children(1).last().addClass("dv-details");

$(this).children(0).animate({
height: "100px",
width: "95%",
opacity: 1,
top: pos[index].top,
left: pos[index].left
}, 1000, "swing");
});
}


function collapsed() {
if ($(".wrapper").first().hasClass("cv-wrapper")) return;

updatePositions();
$(".wrapper").each(function(index) {
$(this).removeClass("dv-wrapper gv-wrapper");
$(this).addClass("cv-wrapper");

$(this).children(0).css({
opacity: 0.8,
top: pos[index].top,
left: pos[index].left
});
});

updatePositions();
$(".wrapper").each(function(index) {
$(this).children(0).children(0).removeClass("dv-video gv-video");
$(this).children(0).children(1).removeClass("dv-details gv-details");
$(this).children(0).children(0).first().addClass("cv-video");
$(this).children(0).children(1).last().addClass("cv-details");

$(this).children(0).animate({
height: "50px",
width: "94%",
opacity: 1,
top: pos[index].top,
left: pos[index].left
}, 1000, "swing");
});

}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
counter-reset: number;
background-color: #ffffff;
padding: 24px;
}

i.fas {
margin: 5px;
}

i.fas:hover {
background-color: white;
}

.container {
width: 500px;
min-height: 90vh;
margin: 0 auto;
background-color: #ADC2A9;
border: 1px dotted gray;
font-size: 0.7em;
position: relative;
}

.wrapper {
margin: 10px 10px;
/* to debug enable the color */
/*background-color: darkcyan;*/
}

.record {
position: absolute;
width: 95%;
top: 0px;
left: 0px;
background-color: #D3E4CD;
}

.record:first-child:before {
counter-increment: number;
content: counter(number);
position: absolute;
top: 10%;
left: 10%;
font-size: 23px;
color: blue
}

.video {
width: 200px;
height: 100px;
background: linear-gradient(white 40%, #5e819ef8);
}


/* list view */

.dv-wrapper {
height: 100px;
width: 95%;
float: left;
}

.dv-video {}

.dv-details {
position: absolute;
width: calc(100% - 200px);
top: 0px;
right: 0px;
float: right;
padding-left: 10px;
overflow: hidden;
}


/* grid view */

.gv-wrapper {
height: 100px;
width: 200px;
float: left;
}

.gv-video {
float: left;
}

.gv-details {
position: absolute;
left: 0px;
bottom: 0px;
padding-left: 10px;
overflow: hidden;
}


/* collapsed view */

.cv-wrapper {
height: 50px;
width: 80%;
}

.cv-video {
float: left;
display: none;
}

.cv-details {
padding-left: 10px;
overflow: hidden;
}

.details p {
width: 100%;
text-overflow: ellipsis;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet" />

<div style="margin: 0 50%; width: 100px; transform: translate(-50%);">
<i class="fas fa-list" onclick="detailed()"></i>
<i class="fa fa-th" onclick="grid()"></i>
<i class="fas fa-bars" onclick="collapsed()"></i>
</div>
<div class="container">
<div class="dv-wrapper wrapper">
<div class="record">
<div class="video dv-video"></div>
<div class="details dv-details">
<p>1 Lorem ipsum dolor sit amet consectetur adipiorem ipsum dolor sit amet consectetur adipisicing elit. Deserunt, dolor.</p>
</div>
</div>
</div>
<div class="dv-wrapper wrapper">
<div class="record">
<div class="video dv-video"></div>
<div class="details dv-details">
<p>2 Lorem ipsum dolor sit amet consectetur adipisicing elit. Deserunt, dolor.</p>
</div>
</div>
</div>
<div class="dv-wrapper wrapper">
<div class="record">
<div class="video dv-video"></div>
<div class="details dv-details">
<p>3 Lorem ipsum dolor sit amet consectetur adipisicing elit. Deserunt, dolor.</p>
</div>
</div>
</div>
<div class="dv-wrapper wrapper">
<div class="record">
<div class="video dv-video"></div>
<div class="details dv-details">
<p>4 Lorem ipsum dolor sit amet consectetur adipisicing elit. Deserunt, dolor.</p>
</div>
</div>
</div>
<div class="dv-wrapper wrapper">
<div class="record">
<div class="video dv-video"></div>
<div class="details dv-details">
<p>5 Lorem ipsum dolor sit amet consectetur adipisicing elit. Deserunt, dolor.</p>
</div>
</div>
</div>

</div>

How do i change table/grid view to tile view

CSS:

.tiled { float: left; margin: 7.5px; background: #B50000; } 

JS:

$(function() {
$( "#button" ).click(function() {
$("#tablestyle").removeClass("tablestyle tableviewtop textaligncenter");
document.getElementById('tabletr').style.display='none';
$("#tablestyle").addClass("rolesbox");
//$(".textaligncenter").addClass("title");
$(".tile td").addClass("title");
$(".tile").addClass("tiled");
$("#tabletr").addClass("content");

});
});

JSFiddle:

Working code



Related Topics



Leave a reply



Submit