Log in to like this post! How to Get Started with the Ignite UI Layout Manager Marina Stoyanova / Tuesday, October 1, 2013 Layout Manager provides a range of five different layouts for your web application. This control works over HTML page, by rearranging the elements depending on the layout you have selected. The Layout Manager gives you an easy-to-use alternative to manually making layout through elements. So let’s look at the different layouts and how to initialize them. For that purpose we will be making an application that allows the users to select the appropriate styling for their needs. Changing the Layout To begin with, you need a way to select the different layouts so here comes the Ignite UI control Combo Box. With the igCombo control you can create drop downs that accept text entries as well as options selected from the items list. This jQuery widget has a lot of useful events such as: selectionChanged, activeItemChanged, textChanged. The event we are going to use in our application is selectionChanged, but more about that later - first let’s see how to add combo box. The following lines demonstrate how to configure the control and how to bind data using jQuery. First define a target element. <select id="comboTarget">select> Bind data. You have to define the data, set the data source and then configure the text and the value fields. <script type="text/javascript"> $(function () { var layout = [ { "Name": "Flow" }, { "Name": "Grid" }, { "Name": "Vertical" }, { "Name": "Border" }, { "Name": "Column" } ]; $("#comboTarget").igCombo({ dataSource: layout, textKey: "Name", valueKey: "Name", width: "200px", autoComplete: true }); }); script> Now that we have created our combo box, we want it to display the various layouts depending on the users choice. As we said the selectionChanged event comes in handy here. As you can see in the documentation ui.items helps us obtain reference to array of new selected items. Probably now is the time to say that the supported layouts by the Layout Manager are: o Border layout o Column layout o Flow layout o Grid layout o Vertical layout That is why the data source names and values are equivalent to those layouts. We are going to use a switch operator to help us with the changes that occur. selectionChanged: function (evt, ui) { var changed = ui.items[0]; var option = changed.value; switch (option) { case "Flow": . . . break; case "Grid": . . . break; case "Column": . . . break; case "Vertical": . . . break; case "Border": . . . break; } } Shortly that is how to initialize Combo Box. You can find more information about Combo box and its features on the products page. Layout Manager As you will see all of the layouts adjust based on the viewport of the browser. To set up the Layout Manager you just need to write the following lines: $("#layout").igLayoutManager({ layoutMode: "flow" }); The layoutMode is the option that allows you to choose which layout to be visualized. In the preceding lines the layoutMode is set to flow, that means we have chosen the Flow Layout. Before every initialization of a layout we use the destroy method of the control, because we want to remove the previously selected layout and visualize the new one on its place. In this application we will take the data from markup. Just, so that you know for the flow and vertical layouts you can use items or itemsCount options. Items is an array of descriptions, meaning that you can set various height and width for the different items. With the second option you can set the number of items to render, they will have the same size. If you choose the previous options the items will be generated automatically and you can set content in the itemRendered event. Anyway as we said we are using data from markup. First we will need to define a target element like that: <div id="layout" style="width:100%;"> We are using separate HTML code for the different layouts, because border and column layouts for instance need specific classes to arrange the elements on the page. At the beginning of our JS code we hide all of the HTML content and everywhere we need to visualize some part we call it with the help of the show() function. Let’s first look at the Border Layout. Border Layout It divides the container into few section: heading, footer,body,left and right sides. To say which element in which section to be situated we use the respective class for each region. HTML <div id="border"> <div class="left"> <p id="l"> <h3>Imagesh3> <ul> <li>Natureli> <li>Animalsli> <li>Mountainsli> <li>Oceanli> ul> p> div> <div class="right"> <p id="r"> <h3>Galleryh3> <img src="http://cdn.morguefile.com/imageData/public/files/g/greyerbaby/preview/fldr_2012_05_20/file2341337572086.jpg" width="150" height="150"/> <img src="http://cdn.morguefile.com/imageData/public/files/h/hotblack/preview/fldr_2010_07_03/file8281278162138.jpg" width="150" height="150"/> <img src="http://cdn.morguefile.com/imageData/public/files/s/seemann/preview/fldr_2010_02_01/file9871265088249.jpg" width="150" height="150"/> <img src="http://cdn.morguefile.com/imageData/public/files/m/melodi2/preview/fldr_2010_01_10/file8201263121775.jpg" width="150" height="150"/> <img src="http://cdn.morguefile.com/imageData/public/files/a/ajjoelle/preview/fldr_2009_12_12/file9941260680478.jpg" width="150" height="150"/> p> div> <div class="center"> <p> <h3>Informationh3> <img src="http://cdn.morguefile.com/imageData/public/files/g/greyerbaby/preview/fldr_2012_05_20/file2341337572086.jpg" width="500" height="400" /> <p> Nature, in the broadest sense, is equivalent to the natural, physical, or material world or universe. "Nature" refers to the phenomena of the physical world, and also to life in general. It ranges in scale from the subatomic to the cosmic. The word nature is derived from the Latin word natura, or "essential qualities, innate disposition", and in ancient times, literally meant "birth".[1] Natura was a Latin translation of the Greek word physis (), which originally related to the intrinsic characteristics that plants, animals, and other features of the world develop of their own accord.[2][3] The concept of nature as a whole, the physical universe, is one of several expansions of the original notion; it began with certain core applications of the word by pre-Socratic philosophers, and has steadily gained currency ever since. This usage was confirmed during the advent of modern scientific method in the last several centuries.p> <p> Within the various uses of the word today, "nature" often refers to geology and wildlife. Nature may refer to the general realm of various types of living plants and animals, and in some cases to the processes associated with inanimate objects the way that particular types of things exist and change of their own accord, such as the weather and geology of the Earth, and the matter and energy of which all these things are composed. It is often taken to mean the "natural environment" or wildernesswild animals, rocks, forest, beaches, and in general those things that have not been substantially altered by human intervention, or which persist despite human intervention.p> p> div> <div class="header">My Gallerydiv> <div class="footer">Ignite UI Layout Manager div> div> jQuery case "Border": $("#border").show().igLayoutManager({ layoutMode: "border", borderLayout: { leftWidth: "10%", rightWidth: "20%" } }); break; The preceding code will look like this: Column Layout The main idea of the column layout is that the container is divided into 12 columns. This layout is similar to Bootstrap. You can have separate rows, each one of which could be split into one to twelve columns. To implement that layout you will have to assign a rowclass to a tag and a colN class to its children. N defines how many column(s) the element takes up. For example if you want your row to have only one column you have to use col12 class and etc. We need to use the “ig-layout-col” class, that is why we call the addClass() jQuery function in the initialization of this layout. HTML <div class="row"> <div class="col12"> <p> <h2 id="myGal">My Galleryh2> p> div> div> <div class="row"> <div class="col2"> <p> <h3>Image 1h3> <img src="http://cdn.morguefile.com/imageData/public/files/g/greyerbaby/preview/fldr_2012_05_20/file2341337572086.jpg" width="150" height="150"/> p> div> <div class="col2"> <p> <h3>Image 2h3> <img src="http://cdn.morguefile.com/imageData/public/files/h/hotblack/preview/fldr_2010_07_03/file8281278162138.jpg" width="150" height="150"/> p> div> <div class="col2"> <p> <h3>Image 3h3> <img src="http://cdn.morguefile.com/imageData/public/files/s/seemann/preview/fldr_2010_02_01/file9871265088249.jpg" width="150" height="150"/> p> div> <div class="col2"> <p> <h3>Image 4h3> <img src="http://cdn.morguefile.com/imageData/public/files/m/melodi2/preview/fldr_2010_01_10/file8201263121775.jpg" width="150" height="150"/> p> div> <div class="col2"> <p> <h3>Image 5h3> <img src="http://cdn.morguefile.com/imageData/public/files/a/ajjoelle/preview/fldr_2009_12_12/file9941260680478.jpg" width="150" height="150"/> p> div> <div class="col2"> <p> <h3>Image 6h3> <img src="http://cdn.morguefile.com/imageData/public/files/r/RED/08/l/1377852969x7n59.jpg" width="150" height="150"/> p> div> div> <div class="row"> <div class="col6"> <p> <h3>Informationh3> <img src="http://cdn.morguefile.com/imageData/public/files/g/greyerbaby/preview/fldr_2012_05_20/file2341337572086.jpg" width="400" height="300" /> p> div> <div class="col6"> <p> Nature, in the broadest sense, is equivalent to the natural, physical, or material world or universe. "Nature" refers to the phenomena of the physical world, and also to life in general. It ranges in scale from the subatomic to the cosmic. The word nature is derived from the Latin word natura, or "essential qualities, innate disposition", and in ancient times, literally meant "birth". Natura was a Latin translation of the Greek word physis (), which originally related to the intrinsic characteristics that plants, animals, and other features of the world develop of their own accord. p> <p> Within the various uses of the word today, "nature" often refers to geology and wildlife. Nature may refer to the general realm of various types of living plants and animals, and in some cases to the processes associated with inanimate objects the way that particular types of things exist and change of their own accord, such as the weather and geology of the Earth, and the matter and energy of which all these things are composed. It is often taken to mean the "natural environment" or wildernesswild animals, rocks, forest, beaches, and in general those things that have not been substantially altered by human intervention, or which persist despite human intervention.p> div> div> jQuery case "Column": $('#layout').addClass("ig-layout-col").children().hide(); $(".row").show(); $('#layout').igLayoutManager({ layoutMode: "column", }); break; Flow and Vertical Layouts In Flow Layout the elements are arranged from left to right in inline-blocks and in vertical layout the items are ordered from top to bottom – single column arrangement. The HTML code that they are using is the same as the above mentioned, only the classes are skipped. You can use some CSS code to change the width and height of the various items. Flow Layout jQuery case "Flow": $('#flowlayout').igLayoutManager("destroy"); $("#flowlayout").show().igLayoutManager({ layoutMode: "flow" }); break; Vertical Layout jQuery case "Vertical": $('#flowlayout').igLayoutManager("destroy"); $("#flowlayout").show().igLayoutManager({ layoutMode: "vertical" }); break; Grid Layout As you can figure out from the name, this layout arrange the items in grid system. This layout needs to generate the items and in the itemRendered event handler we actually set the content for the rendered items. We use the rearrangeItems option because it specifies whether the items should rearrange to fit in the container when it is resized. Pay attention that it only has effect when fixed columnWidth option is set. So the code for the grid layout will look like this: jQuery case "Grid": $('#gridlayout').igLayoutManager("option", "destroyItems",true).igLayoutManager("destroy"); var flowItems = $("#flowlayout").children(); $('#gridlayout').show().on("iglayoutmanageritemrendered", function (event, args) { var currentItem = $(flowItems[args.index]).clone(); args.item.append(currentItem); }); $('#gridlayout').igLayoutManager({ layoutMode: "grid", gridLayout: { rearrangeItems: true, useOffset: false, columnWidth: 250, columnHeight: 250, cols: 3, rows: 3 }, items: [ { rowSpan: 1, colSpan: 1 }, { rowSpan: 1, colSpan: 1 }, { rowSpan: 1, colSpan: 1 }, { rowSpan: 1, colSpan: 1 }, { rowSpan: 1, colSpan: 1 }, { rowSpan: 1, colSpan: 1 }, { rowSpan: 1, colSpan: 1 }, { rowSpan: 1, colSpan: 1 } ] }).css("minHeight", "500px"); break The Ignite UI Tile Manager control is based on the Grid layout, so as you can assume it offers different interesting options. You can check either the products’ page for more information or the documentation. You can find the application’s sample here. You can follow us on Twitter @Infragistics and stay in touch on Facebook, Google+ and LinkedIn!