Log in to like this post! Using Load on Demand with Infragistics jQuery ComboBox Atanas Dyulgerov / Wednesday, April 11, 2012 The Infragistics jQuery combo box is a very useful control that allows you to show lists of data in a very customizable way while also providing you with selection. It allows you to use numerous types of data sources, it is quite flexible when it comes to styling (take a look at an article in which I showed you how to make it look as a multicolumn combo box) and works fast. One of the very nice features of the combo box is the load on demand feature. When you work with big lists of data, performance is always a concern. Naturally you want your application to be responsive and fast no matter what quantity or type of data you supply it with. The build in mechanism “load on demand” provides you exactly with this functionality. It turns on the data virtualization of the combobox and downloads only the information that is needed to load the items on the screen. The first combo shows a combobox loaded with items that come from a odata netflix service. There are 82801 items, but only 25 are downloaded initially. The second screenshot shows that when you scroll down and more items should be displayed on the screen the list is grayed out to show progress (you can provide a busy indicator there) the backed downloads the next batch of 25 items and now 50 out of all the 82801 items are downloaded. This batch download is much much faster than the download of all items in the loading of the app and much more responsive. In this article I’ll show you how to enable this feature. But first take a look at the base code that we’ll use to build the sample. <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title>Load on Demand sample</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script> <script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js" type="text/javascript"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript" src="js/infragistics.loader.js"></script> <script type="text/javascript"> $.ig.loader({ scriptPath: "js/", cssPath: "css/", resources: "igCombo" }); </script> <style type="text/css"> .boxed { border: 1px solid Gray; margin: 3px; padding: 5px; border-radius: 3px; font-weight: bold; } </style> <script type="text/javascript"> $.ig.loader(function () { $("#combo").igCombo({ responseDataKey: "d.results", dataSource: 'http://odata.netflix.com/Catalog/Titles?$format=json&$callback=?', filteringType: "remote", width: "250px", textKey: "Name", valueKey: "Id", autoComplete: true, headerTemplate: "<div class='boxed'>Available Movies</div>", footerTemplate: "<div class='boxed'>Movie Count: {0} / {3}</div>", itemTemplate: "<div>${Name} (${ReleaseYear})</div>", nullText: "Please, select a movie" }); }); </script> </head> <body> <div> <input id="combo" /> </div> </body> </html> The first thing we do is add the required css and js files. We need the jQuery, jQuery UI and jQuery template packages. The Infragistics styles and scripts we load using the IG Loder. Then we provide a small template for the header and footer of the combobox dropdown (you can see them in the screenshot before – header says “Avalable Movies” and the footer displays how many items are loaded and what is the total number). The last part of the code above is the combobox itself. As you see we provide the address of the service that will use, and some basic styling. The interesting thing to note is the filteringType. When you specify “remote” the combobox will allow the filter criteria to be sent to the service and when we are finished with the load and demand filtering will work no matter that all items are not actually available on the client. This is standard thing associated with data virtualization. So now that we have that combo here is how to enable the load on demand: First we need to set the virtualization property to true and provide settings for the loadOnDemandSettings – enabled has to be true and we need to give a size for the pageSize. Here is the code that does this: $.ig.loader(function () { $("#combo").igCombo({ loadOnDemandSettings: { enabled: true, pageSize: 25 }, responseDataKey: "d.results", dataSource: 'http://odata.netflix.com/Catalog/Titles?$format=json&$callback=?', filteringType: "remote", width: "250px", textKey: "Name", valueKey: "Id", virtualization: true, autoComplete: true, headerTemplate: "<div class='boxed'>Available Movies</div>", footerTemplate: "<div class='boxed'>Movie Count: {0} / {3}</div>", itemTemplate: "<div>${Name} (${ReleaseYear})</div>", nullText: "Please, select a movie" }); }); This is all you need to turn on the feature. You only have to consider what the right pageSize is for your need. Make sure the number is enough to cover all items that have to be displayed and a a little buffer (the number should normally be larger than the actual shown elements to avoid blank page until they load). Also make sure the number is not too big to slow down the data transfer from your service. Look for a balanced solution. I hope this has been interesting and useful. Have an awesome day!