Log in to like this post! jQuery grid with DOM virtualization [Infragistics] Murtaza Abdeali / Wednesday, January 19, 2011 I am proud to announce that Infragistics just shipped NetAdvantage for Web Developers CTP, a product that is geared towards helping web developers building modern web sites. It is built on top of jQuery, the most popular JavaScript framework out there today. It has almost been a year in the making of this great product and we hope that you will like what we have in this CTP package. You can read additional product details here and don’t forget to check out the live running samples here. However, in this post I would like to highlight one neat feature of the product which makes it very unique. That feature is DOM virtualization in the jQuery grid control. We know that sometimes displaying data could become quite problematic and impact performance in web applications, especially large amounts of data. The more data a client requests, the more heavy the HTML becomes in a server based data binding situations. This causes page load time and rendering delays and affects the overall application experience. When the grid is on the client, the developer has to now be concerned with browser memory foot print, along with CPU consumption while the grid is in use. With DOM virtualization in the jQuery client grid, we hope to have raised the bar for the amount of data that can be displayed without hitting major performance pitfalls. First, the grid is completely rendered on the client and is a purely JavaScript based controls, this means that the data doesn’t need to be carried inside of the HTML tables from the server anymore, but all the DOM is generated on the client. This improves the load time and the overall server to client transmission of data and eventually your web pages. Second and the most important aspect of DOM virtualization is that is only renders the rows and columns that is visible to the end-user, it doesn’t generate the entire table with the data in your datasource. This in-turn makes the grid light weight with small memory footprint and quick with the overall data rendering. As the user scrolls, the jQuery grid uses the same cell (<td>) elements to recycle the content and update its data, giving the end-user and illusion that they are actually scrolling the grid, but actually the grid is simply re-using the same elements to display new set of scrolled data. To demonstrate this, let’s consume the Netflix movie data for titles that is exposed via an oData feed, and populate the jQuery grid with it. First we need to get resources needed, the JavaScript and CSS classes. Styling is based on Theme Roller so same CSS class references are used in most cases to grab the look and feel for the control elements. We are going to be using the grid and editor JavaScript files. <link id="lnkThemeCSS" type="text/css" href="./Styles/jquery.ui.custom.css" rel="stylesheet" /> <link type="text/css" href="./Styles/ig.ui.grid_VD.css" rel="stylesheet" /> <link type="text/css" href="./Styles/ig.ui.shared.css" rel="stylesheet" /> <link type="text/css" href="./Styles/ig.ui.editors.css" rel="stylesheet" /> <script src="http://code.jquery.com/jquery-1.4.4.js" type="text/javascript"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.js" type="text/javascript"></script> <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script> <script type="text/javascript" src="/Scripts/jquery.ui.core.js"></script> <script type="text/javascript" src="./Scripts/jquery.ui.widget.js"></script> <script type="text/javascript" src="./Scripts/ig.util.js"></script> <script type="text/javascript" src="./Scripts/ig.dataSource.js"></script> <script type="text/javascript" src="./Scripts/ig.dataSource-en.js"></script> <script type="text/javascript" src="./Scripts/ig.ui.shared.js"></script> <script type="text/javascript" src="./Scripts/ig.ui.grid-en.js"></script> <script type="text/javascript" src="./Scripts/ig.ui.grid.framework.js"></script> <script type="text/javascript" src="./Scripts/ig.ui.grid.filtering-en.js"></script> <script type="text/javascript" src="./Scripts/ig.ui.grid.filtering.js"></script> <script type="text/javascript" src="./Scripts/ig.ui.grid.sorting-en.js"></script> <script type="text/javascript" src="./Scripts/ig.ui.grid.sorting.js"></script> <script type="text/javascript" src="./Scripts/ig.ui.grid.paging-en.js"></script> <script type="text/javascript" src="./Scripts/ig.ui.grid.paging.js"></script> <script type="text/javascript" src="./Scripts/ig.ui.editors.js"></script> Next, we need to put an empty HTML table on the body of the page, which we will use to convert it to a jQuery Grid. <table id="grid1"></table> Now we need to get the JSONP data from the Netflix feed. For that we can simply call the service and use the igDataSource to store the data on the client before we bind it to the grid. var url = "http://odata.netflix.com/Catalog/Titles?$format=json&$callback=?"; var jsonp = new $.ig.JSONPDataSource({ dataSource: url, responseDataKey: "d.results" }); One we have the data and the table DOM element, we now need to bind all the data to the table element and enable grid features, especially virtualization. All the properties are attached to the grid element and the DOM element with id ‘grid1’ is converted into an Infragistics jQuery grid with paging, sorting and filtering features enabled. $("#grid1").igGrid({ virtualization: true, autoGenerateColumns: false, rowTemplate: "<tr><td> ${Name} </td> <td> <img width='110' height='150' src='${BoxArt.LargeUrl}'></img></td><td> <p> {{html Synopsis}} </p> </td></tr>", columns: [ { name: "Movie Name", dataKeyField: "Name", width: "150px" }, { name: "Image", dataKeyField: "BoxArt", width: "120px" }, { name: "Movie Synopsis", dataKeyField: "Synopsis", width: "400px" } ], responseDataKey: "d.results", dataSource: jsonp, headerCaption: "NetFlix OData , JSONP, paging, sorting", scrollbars: true, height: '600px', features: [ { name: 'Paging', pageSize: 100000 }, { name: 'Sorting' }, { name: 'Filtering', filterDropDownItemIcons: false, filterDropDownWidth: 200 } ] }); We have now successfully created a fully styled jQuery client Grid with the jQuery plugin in NetAdvantage for Web Developers. The grid supports paging, filtering and sorting along with virtualization. Click here to see this sample running live. Click here to download the sample code. We encourage you to download the CTP and please send us your feedback. You can post your queries on the forums here. The final release of the product will be shipped in April. If you have any other product related question, please send an email to taz@infragistics.com