ASP.NET: Responsive GapFree MultiColumn Grids using Nested.js

DEMO DOWNLOAD MultiColumn Dynamic Grid Layouts are very popular nowadays and Pinterest , the fastest growing social network i...





MultiColumn Dynamic Grid Layouts are very popular nowadays and Pinterest, the fastest growing social network is a familiar real time example of the same. There are many jQuery plugins available for creating such layouts starting from the jQuery Masonry plugin.

Recently, I discovered the existence of a new dynamic grid plugin called Nested developed by Jonas Blomdin that can be used to create a gap free, responsive dynamic grid layout. He had explained clearly how this plugin is different from the established masonry plugin here and that is the reason why I chose the Nested jQuery plugin along with FancyBox jQuery Plugin to create an image portfolio that consists of responsive multicolumn image grids. In this post, I am going to explain how to create responsive multicolumn dynamic grids in ASP.NET using Nested.js plugin.

There are three things that this plugin do,

  • Creates a matrix of all elements and creates a multi column grid.
  • Scans the matrix for gaps and tries to fill them by re-ordering the elements.
  • Resize any element at the bottom of the grid that is bigger (or smaller) than the gap to make the grid completely gap-free.

Steps to follow to implement this,

1. Download Nested jQuery plugin from here.

2. Add the jQuery.nested.js and style.css file from the download to your asp.net project.

3. We are going to display images of varying size using Repeater control. In this scenario, there are two parameters that is required for each grid, one is the value for image source, and the other is the cssclass for each grid.

To understand this let us see how it works in simple html. Each grid item should use css class as explained below,

<div id="container">
  <div class="box size11"></div>
  <div class="box size12"></div>
  <div class="box size21"></div>
  <div class="box size22"></div>
  ...
</div>

Sizing of items are handled by adding sizeWH where W is the number of columns the box shall use and H is the number of rows the box shall use. For example, size12 equals to 1 column and 2 rows, to display an image in this grid, the image should be of 50 X 100 in size.

The base column and row size is set by minWidth option and default is 50. This option can be changed anytime using,

$("#container").nested({minWidth: 100});
To implement the same in asp.net, copy and paste the below code in .aspx file. Make sure you have included the necessary script and css files mentioned in point 1. I have used 27 images in various sizes as explained above to create this portfolio, for example size11 - 50 X 50, size 21- 100 X 50. etc. You can use images or any other content, such as text, buttons and other controls as content for the grid.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Responsive MultiColumn Grid Example</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="jquery.nested.js" type="text/javascript"></script>
    <script type="text/javascript" >
     $(function() {     
       $('#container').nested(); 
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="container">
        <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
               <div class="<%#Eval("CssClassVal")%>">
                   <img src="<%# Eval("SmallUrl")%>" alt="" />                   
               </div>            
           </ItemTemplate>
        </asp:Repeater>
    </div>
    </form>
</body>
</html>

4. Use the below code in the code-behind page, here I am building a list that consists of information required for rendering the image such as the size of the image to be supplied to css class, (eg. 11,21.etc) and the path of image to be used by the src attribute. I have stored all images in Images/images_small folder and followed the same naming convention for all the images as in 'img_x.jpg', x starting from 1 to 27.


public class ImageAttributes
    {
        public string SmallUrl { get; set; }
        public string CssClassVal { get; set; }
    }

    public static class PopulateRepeater
    {
        static List<ImageAttributes> objList;
        public static IEnumerable<ImageAttributes> GetData()
        {
            ImageAttributes obj;
            objList = new List<ImageAttributes>();
            //Image size for each image used in the project eg. size53 - 250x150 px
            int[] csssize = new int[]{53,42,34,11,22,45,43,24,37,32,53,23,12,21,23,22,11,
                64,11,12,23,22,11,21,12,11,11};
            for (int i = 1; i <=27; i++)
            {
                obj = new ImageAttributes();
                obj.SmallUrl = String.Format("Images/images_small/img_{0}.jpg",i);                          int size=csssize[i-1];
                obj.CssClassVal = String.Format("box size{0}",size);
                objList.Add(obj);
            }
            return objList;
        }

5. Bind Repeater control with values from PopulateRepeater Class in Page load method as shown below,


     protected void Page_Load(object sender, EventArgs e)
        {
            Repeater1.DataSource = PopulateRepeater.GetData();
            Repeater1.DataBind();
        }

6. That is all, now build the project and open .aspx file in the browser to see the results. Resize browser window to know how the image grids re-align automatically according to the window size.




Caution:

There is a bug in this plug-in that causes the browsers to freeze due to an infinite loop when the viewport is reduced to less than the size of the widest element in the grid. There is a local fix available here. So whenever you use the jquery.nested.js file, make sure you edit the _renderGrid() method in it as mentioned in the issues page.


Please leave your comments and queries about this post in the comment sections in order for me to improve my writing skills and to showcase more useful posts. Thanks for reading!!




Subscribe to GET LATEST ARTICLES!


Related

Responsive Design 3392651454871117275

Post a Comment

  1. We are so delighted to be your go-to animation studio! Whether you need a logo animation, animated video, or TV commercial, we’ve got just the artistic touch. Experts at our animation video production are happy to take your needs and elevate them with their unique style. We can work on a variety of different video content types including social media animations, corporate animations, business animations, cartoon animations, brand animations and what not.

    ReplyDelete
  2. Hi, I am John Smith I am Web Developer, It is an amazing blog thanks for the sharing the blog. Frantic infotech provide the php web development company such as an information about software development for costumer service. Frantic infotech also provide the Hardware Mobile App Development. The development of advanced web applications is Orient Software’s specialty and we will successfully fulfill all your web application development requirements, from small-sized to wider-ranged projects.

    ReplyDelete
  3. Make your Magento application management easy with the best magento dedicated hosting. Devrims offers a next-gen managed cloud hosting platform that allows store owners & digital agencies to efficiently run their eCommerce store with high performance, fully managed and no server downtime.

    ReplyDelete
  4. Green card holders who transport between home nation and USA or individuals who just got green card status (Any Age) will be qualified for new settlers protection plans. The green card holders who for all time gets comfortable USA will be qualified to buy Significant clinical protection plans like Blue Cross Blue Safeguard, Aetna, Song of devotion, Cigna, UnitedHealthCare and some more.. in light of the age. If it's not too much trouble, call us for more nitty gritty data. Get new immigrant insurance at affordable price so do contact us.

    To know more about this visit: https://www.visitorsinsurance.com/Green-card-Immigrant-Plans.asp

    Contact US:
    Location: 425 Huehl Road,Suite 22-A,Northbrook,IL 60062
    Phone : 1-847-897-5120 | Fax : 1.847.897.5130 | Toll Free : 1-800-344-9540
    WhatsApp : 1-847-897-5120 | Email: info@visitorsinsurance.com
    Website: http://www.visitorsinsurance.com
    http://www.facebook.com/myvisitorsinsurance
    https://www.trustpilot.com/review/www.visitorsinsurance.com
    http://www.linkedin.com/company/visitorsinsurance

    ReplyDelete
  5. Asp.Net is a server side sripting language and thier abbreviation is active server pages,new and enhance technolgy.When I was using the responsive gap free multi columns grid using node js.This is mainly used to backend development and Iam writing research paper help service that is submitted by university on the given deadline.

    ReplyDelete
  6. After seeing this post only i am realizing Pinterest using jQuery for their Masonry plugin for layout appearance. Hereafter whenever i see grid layouts in Pinterest, definitely this post will come to my mind. Thanks for sharing such a knowledgeable post for us. Keep sharing these kind of post which is useful for us.
    DUI Lawyers In Arlington

    ReplyDelete
  7. I'm glad to hear that the post was informative for you and that it helped you to recognize the use of jQuery for Pinterest's Masonry plugin. It's interesting to learn about the technologies used in creating various websites and applications, and I hope this knowledge comes in handy for you in the future. Thank you for your feedback and for reading the post! Bankruptcy near me attorney

    ReplyDelete
  8. Explore WebPays that proactively protect your business and customers against fraud and data breaches without impacting real transactions. Get ready to leverage a unified and all-in-one credit card payment solution to accept credit card payments in a secure environment.

    ReplyDelete
  9. Elevate your business with our cutting-edge white label payment gateway solutions, tailored to meet your unique needs and customer expectations. Are you planning to start your own payment gateway business today ? Reach us out and get to know everything in details.



    ReplyDelete

emo-but-icon

SUBSCRIBE


item