<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Nathaniel Engelsen &#187; Pager</title>
	<atom:link href="http://nathanielengelsen.com/tag/pager/feed/" rel="self" type="application/rss+xml" />
	<link>http://nathanielengelsen.com</link>
	<description></description>
	<lastBuildDate>Thu, 03 Dec 2009 13:03:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>MvcContrib Ajax Sorting and Paging with jQuery</title>
		<link>http://nathanielengelsen.com/2009/07/mvccontrib-ajax-sorting-and-paging-with-jquery/</link>
		<comments>http://nathanielengelsen.com/2009/07/mvccontrib-ajax-sorting-and-paging-with-jquery/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 00:22:25 +0000</pubDate>
		<dc:creator>nathaniel engelsen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[MvcContrib]]></category>
		<category><![CDATA[Pager]]></category>

		<guid isPermaLink="false">http://nathanielengelsen.com/?p=132</guid>
		<description><![CDATA[I started the "MvcContrib Ajax Sorting and Paging with jQuery" project at CodePlex, offering a jQuery plugin to accelerate using ajax with MvcContrib grids.]]></description>
			<content:encoded><![CDATA[<p>I started a new project at Codeplex for the MvcContrib/jQuery tinkering I&#8217;ve been doing. You can find it <a href="http://mvcajax.codeplex.com/">here</a>, and it&#8217;s titled &#8220;MvcContrib Ajax Sorting and Paging with jQuery&#8221;.  I created a jQuery plugin that wraps around the MvcContrib Grid and Pager outputs (no more extending MvcContrib), and utilizes jQuery.ajax() to offers server-side paging and sorting.  In addition, I created some new tidbits:</p>
<ul>
<li>a new HtmlHelper I wrote outside of MvcContrib, entitled PageDropDown, that gives a &#8220;page x of y&#8221; dropdown.</li>
<li>a scrollable grid with fixed headers that is about 90% complete (separate issues in Firefox and IE)</li>
</ul>
<p>My good friend Chris made me realize that I don&#8217;t need to extend MvcContrib at all &#8212; by utilize jQuery, I can augment the MvcContrib library output and convert the grid header and pager items into links.  As long as the user utilizes the right controller signature, everything works excellently.</p>
<p>I invite everyone to check out my project <a href="http://mvcajax.codeplex.com/">&#8220;MvcContrib Ajax Sorting and Paging with jQuery&#8221;</a>, and let me know what you think.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fnathanielengelsen.com%2F2009%2F07%2Fmvccontrib-ajax-sorting-and-paging-with-jquery%2F&amp;partner=sociable" title="Print"><img src="http://nathanielengelsen.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fnathanielengelsen.com%2F2009%2F07%2Fmvccontrib-ajax-sorting-and-paging-with-jquery%2F&amp;title=MvcContrib%20Ajax%20Sorting%20and%20Paging%20with%20jQuery&amp;bodytext=I%20started%20the%20%22MvcContrib%20Ajax%20Sorting%20and%20Paging%20with%20jQuery%22%20project%20at%20CodePlex%2C%20offering%20a%20jQuery%20plugin%20to%20accelerate%20using%20ajax%20with%20MvcContrib%20grids." title="Digg"><img src="http://nathanielengelsen.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fnathanielengelsen.com%2F2009%2F07%2Fmvccontrib-ajax-sorting-and-paging-with-jquery%2F&amp;title=MvcContrib%20Ajax%20Sorting%20and%20Paging%20with%20jQuery&amp;notes=I%20started%20the%20%22MvcContrib%20Ajax%20Sorting%20and%20Paging%20with%20jQuery%22%20project%20at%20CodePlex%2C%20offering%20a%20jQuery%20plugin%20to%20accelerate%20using%20ajax%20with%20MvcContrib%20grids." title="del.icio.us"><img src="http://nathanielengelsen.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fnathanielengelsen.com%2F2009%2F07%2Fmvccontrib-ajax-sorting-and-paging-with-jquery%2F&amp;t=MvcContrib%20Ajax%20Sorting%20and%20Paging%20with%20jQuery" title="Facebook"><img src="http://nathanielengelsen.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fnathanielengelsen.com%2F2009%2F07%2Fmvccontrib-ajax-sorting-and-paging-with-jquery%2F&amp;title=MvcContrib%20Ajax%20Sorting%20and%20Paging%20with%20jQuery&amp;annotation=I%20started%20the%20%22MvcContrib%20Ajax%20Sorting%20and%20Paging%20with%20jQuery%22%20project%20at%20CodePlex%2C%20offering%20a%20jQuery%20plugin%20to%20accelerate%20using%20ajax%20with%20MvcContrib%20grids." title="Google Bookmarks"><img src="http://nathanielengelsen.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.dotnetkicks.com/kick/?url=http%3A%2F%2Fnathanielengelsen.com%2F2009%2F07%2Fmvccontrib-ajax-sorting-and-paging-with-jquery%2F&amp;title=MvcContrib%20Ajax%20Sorting%20and%20Paging%20with%20jQuery" title="DotNetKicks"><img src="http://nathanielengelsen.com/wp-content/plugins/sociable/images/dotnetkicks.png" title="DotNetKicks" alt="DotNetKicks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Fnathanielengelsen.com%2F2009%2F07%2Fmvccontrib-ajax-sorting-and-paging-with-jquery%2F&amp;t=MvcContrib%20Ajax%20Sorting%20and%20Paging%20with%20jQuery" title="HackerNews"><img src="http://nathanielengelsen.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fnathanielengelsen.com%2F2009%2F07%2Fmvccontrib-ajax-sorting-and-paging-with-jquery%2F&amp;title=MvcContrib%20Ajax%20Sorting%20and%20Paging%20with%20jQuery&amp;source=Nathaniel+Engelsen+&amp;summary=I%20started%20the%20%22MvcContrib%20Ajax%20Sorting%20and%20Paging%20with%20jQuery%22%20project%20at%20CodePlex%2C%20offering%20a%20jQuery%20plugin%20to%20accelerate%20using%20ajax%20with%20MvcContrib%20grids." title="LinkedIn"><img src="http://nathanielengelsen.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fnathanielengelsen.com%2F2009%2F07%2Fmvccontrib-ajax-sorting-and-paging-with-jquery%2F&amp;title=MvcContrib%20Ajax%20Sorting%20and%20Paging%20with%20jQuery" title="Reddit"><img src="http://nathanielengelsen.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=MvcContrib%20Ajax%20Sorting%20and%20Paging%20with%20jQuery&amp;url=http%3A%2F%2Fnathanielengelsen.com%2F2009%2F07%2Fmvccontrib-ajax-sorting-and-paging-with-jquery%2F" title="Slashdot"><img src="http://nathanielengelsen.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://nathanielengelsen.com/2009/07/mvccontrib-ajax-sorting-and-paging-with-jquery/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Adding AJAX-based server-side paging and sorting to MvcContrib Grid using jQuery</title>
		<link>http://nathanielengelsen.com/2009/07/adding-ajax-based-server-side-paging-and-sorting-to-mvccontrib-grid-using-jquery/</link>
		<comments>http://nathanielengelsen.com/2009/07/adding-ajax-based-server-side-paging-and-sorting-to-mvccontrib-grid-using-jquery/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 01:56:29 +0000</pubDate>
		<dc:creator>nathaniel engelsen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[Grid]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[MvcContrib]]></category>
		<category><![CDATA[Pager]]></category>

		<guid isPermaLink="false">http://nathanielengelsen.com/?p=104</guid>
		<description><![CDATA[One of the biggest challenges of a web-based business application developer involves presenting data to the user in a fast, useable fashion.  Sortable, pageable grids solve this dilemma by introducing the arduous process of creating them.  Leveraging and extending MvcContrib and jQuery to provide fast, asynchronous updates (from data sorted and paged on the server) to the user is a win.]]></description>
			<content:encoded><![CDATA[<p><strong>Edit:</strong> Check out my <a href="http://nathanielengelsen.com/2009/07/mvccontrib-ajax-sorting-and-paging-with-jquery/" title="MvcContrib Ajax Sorting and Paging with jQuery">follow-up to this post</a> for more information on the Codeplex demonstration / proof-of-concept</a> project I&#8217;m working on.</p>
<p>MvcContrib is an excellent, well known Asp.NET MVC resource adding major functionality on top of the recent 1.0 MVC release.  jQuery is an excellent, well-known javascript accelerator library that is tremendously extensible and powerful.  Utilizing them together can improve the speed with which you can get an application into production and enhance the configurability and maintainability of same.  There are pitfalls working with any framework, yes, but these two libraries, on top of the Asp.NET MVC framework, can help us deliver our data quickly and with an AJAXified (AJAXian?) flair.</p>
<p><span id="more-104"></span>jQuery already has many third-party plugins available that  help the developer provide a better UI to their users, and on top of any HTML table to boot.  Unfortunately, these libraries work with the data available on the client, so any sorting or paging done involves the entire data set that has been delivered to the client.  Yes, plenty of commercial components exist that allow a developer to consume a web service or WCF endpoint to provide exactly what we&#8217;re going for, but</p>
<ul>
<li>A: we&#8217;ve all been burned by them before and</li>
<li>B: let&#8217;s do it ourselves anyway.</li>
</ul>
<p>Now, before we get started, a caveat:  While this essay is for the standard MVC Viewengine, I&#8217;ve switched to <a href="http://sparkviewengine.com">Spark</a>, and may have a typo here or there because of it.  Now, to the meat of this course; let&#8217;s take a look at MvcContrib, and the simple way of generating a Grid using the HtmlHelper Grid<> extension.  For starters, take a look at local guru David Hayden&#8217;s short <a href="http://davidhayden.com/blog/dave/archive/2009/06/25/MvcContribGridPagerHelpers.aspx">introductory piece on the Grid and Pager Helpers</a>.  The syntax for using them are as follows:</p>
<pre class="brush: csharp; title: ; notranslate">
&lt;%Html.Grid&lt;AwesomePeople&gt;(&quot;peeps&quot;,
	column =&gt; {
		column.For(c =&gt; c.FirstName);
		column.For(c =&gt; c.LastName);
		column.For(c =&gt; c.Age);
		}
);
%&gt;
&lt;%= Html.Pager((IPagination)ViewData[&quot;peeps&quot;])%&gt;
</pre>
<p>OK, easy enough.  Here we&#8217;re utilizing the Grid<> and Pager HtmlHelper extension methods to create a nice rendered grid and pager widget.  In order to have the plumbing work correctly we have to do one particular thing in our controller:</p>
<pre class="brush: csharp; title: ; notranslate">
public ActionResult Index(int? page)
{
    return View(AwesomePeople.FetchAll().AsPagination(page ?? 1, 25));
}
</pre>
<p>AsPagination wraps your IEnumerable or IQueryable data with IPagination, which adds fields to allow your pager to do what it needs to do &#8212; namely, provide total page and item counts, along with IsFirst and IsLast capability.</p>
<p>To work AJAX into this equation we&#8217;re going to introduce <a href="http://docs.jquery.com/Ajax">jQuery.ajax()</a>:</p>
<pre class="brush: jscript; title: ; notranslate">
 $.ajax({
   type: &quot;POST&quot;,
   url: &quot;some.php&quot;,
   data: &quot;name=John&amp;location=Boston&quot;,
   success: function(msg){
     alert( &quot;Data Saved: &quot; + msg );
   }
 });
</pre>
<p>So where to get started?  While researching this topic, I came across <a href="http://www.c-sharpcorner.com/Blogs/BlogDetail.aspx?BlogId=875">this article</a> by Mike Gold that gave me some clues about how to handle it.  It&#8217;s very easy to get jQuery.ajax() and your controller actions playing nice together, but how then to get the grid to render?  On top of all of this, MvcContrib Grid<> doesn&#8217;t even support sorting!  Where do we begin?</p>
<p>For starters, let&#8217;s determine how to set up our jQuery.ajax() function.  I decided right away that I&#8217;m going to need a javascript function that can be used to provide ajax capability for any grid on our page, even when there are multiple grids.  To accomplish this, I&#8217;ll definitely need to pass into my function the name of the grid&#8217;s parent element (I&#8217;m rewriting the whole grid markup) and the name of the controller action that will serve as my data source.  For sorting purposes, I&#8217;ll need to pass in the column to be sorted upon, and for paging purposes I&#8217;ll need to pull in the page number whose results I&#8217;m looking for.  Finally, I also felt that my javascript function is probably the easiest place to maintain my sort order as well &#8212; luckily that means I won&#8217;t need to pass it in as a parameter.  Here&#8217;s what I came up with:</p>
<pre class="brush: jscript; title: ; notranslate">
function UpdateGrid(griddiv, controller, col, page) {
    // when sorting, page is undefined or the same
    // when paging, column is the same
    if ($(griddiv).attr(&quot;currentpage&quot;) == undefined &amp;&amp; $(griddiv).attr(&quot;sortcol&quot;) == undefined &amp;&amp; $(griddiv).attr(&quot;direction&quot;) == undefined) {
        // init
        $(griddiv).attr(&quot;currentpage&quot;, 1).attr(&quot;direction&quot;, &quot;ASC&quot;).attr(&quot;sortcolumn&quot;, col);
    }
    else {
        if (page !== undefined &amp;&amp; $(griddiv).attr(&quot;currentpage&quot;) !== page) {
            // changing page
            $(griddiv).attr(&quot;currentpage&quot;, page);
        }
        else {
            // page being the same means we're sorting
            if ($(griddiv).attr(&quot;sortcolumn&quot;) == col) {
                // same column means we need to switch ascending and descending
                if ($(griddiv).attr(&quot;direction&quot;) == &quot;ASC&quot;) {
                    $(griddiv).attr(&quot;direction&quot;, &quot;DESC&quot;);
                }
                else {
                    $(griddiv).attr(&quot;direction&quot;, &quot;ASC&quot;);
                }
            }
            else {
                // different column means we're starting with ascending
                $(griddiv).attr(&quot;direction&quot;, &quot;ASC&quot;);
            }
            $(griddiv).attr(&quot;sortcolumn&quot;, col);
        }
    }
	$.ajax({
		type: &quot;POST&quot;,
		url: controller,
		data: ({ ColumnName: $(griddiv).attr(&quot;sortcolumn&quot;), PageNum: $(griddiv).attr(&quot;currentpage&quot;), Controller: controller, Griddiv: griddiv, Direction: $(griddiv).attr(&quot;direction&quot;) }),
		success: function(msg) {
			$(griddiv).html(msg);
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
		    alert(&quot;Data Failed to Sort: &quot; + XMLHttpRequest);
		}
	});
}
</pre>
<p>We&#8217;re using jQuery.attr() to persist the sorted column name, the current page, and the sort direction on the grid parent element.  This way, when a different grid is sorted/paged through, we&#8217;ll be able to come back to our previously sorted grid and pick up right where we left off.  Our grid parent element can then be coded as such:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div id=&quot;awesome_grid&quot; /&gt;
</pre>
<p>Our controller is very straightforward, and is kind enough to send us back the information we&#8217;re sending to it, namely Controller and Griddiv:</p>
<pre class="brush: csharp; title: ; notranslate">
        public ActionResult Sort(string ColumnName, int? PageNum, string GridDiv, string Controller, string Direction)
        {
            // page number is pretty much never null
            // but with the coalescing operation, why be lazy?
            int page = PageNum ?? 1;
            // let's have a default sort order. we're hard coded to our Model, so
            // it's not a concern if we hard code the default sort order.
            string column = (ColumnName ?? &quot;FirstName&quot;) == &quot;undefined&quot; ? &quot;FirstName&quot; : ColumnName;
            // default sort direction.
            string direction = (Direction ?? &quot;ASC&quot;) == &quot;undefined&quot; ? &quot;ASC&quot; : Direction;
            // Linq to SQL data context
            DataLayer.DataContext dc = new DataContext(_conn);
            // AsPagination == from the MvcContrib.Pagination namespace.
            // also taking advantage of the dynamic query library for AJAX
            var peeps = dc.AwesomePeople.OrderBy(column + &quot; &quot; + direction).AsPagination(PageNum ?? 1, pageSize);
            ViewData[&quot;peeps&quot;] = peeps;
            ViewData[&quot;controller&quot;] = Controller;
            ViewData[&quot;griddiv&quot;] = GridDiv;
            return View(PeepsGrid);
        }
</pre>
<p>You can see that we&#8217;re not returning our sorted column name nor the sort direction.  Our javascript function took care of persisting these, so we&#8217;re only returning those items that our component will need so that the grid can create sortable headers and our pager widget can create its paging UI. We&#8217;ll need to create a separate .aspx page that we&#8217;ll use as our grid component, and then use the Grid<> code from above (with some minor changes).  We don&#8217;t need to include much on our control because we&#8217;re combining our model and view in order to get the markup, but then we&#8217;re just returning the markup to our earlier jQuery.Ajax() call &#8212; we&#8217;re not rendering a completely new page.</p>
<p>In order to create a sortable header we need to modify the header of our Grid Column.  Where before we had</p>
<pre class="brush: csharp; title: ; notranslate">
		column.For(c =&gt; c.FirstName);
</pre>
<p>we now need to have</p>
<pre class="brush: csharp; title: ; notranslate">
		column.For(c =&gt; c.FirstName).Header(&quot;&lt;th&gt;&lt;a href=\&quot;javascript:UpdateGrid('&quot; + ViewData[&quot;griddiv&quot;] + &quot;','&quot; + ViewData[&quot;controller&quot;] + &quot;','FirstName');\&quot;&gt;First Name&lt;/a&gt;&lt;/th&gt;&quot;);
</pre>
<p>This is by far my least favorite thing, but I haven&#8217;t extended MvcContrib Grid<> yet. It&#8217;s on my list, and I&#8217;ll post when I get it done. I did, however, extend the pager component.  For starters, you&#8217;ve <a href="http://mvccontrib.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=25281">downloaded the MvcContrib source</a> already, right?  Fire it up, and navigate to MvcContrib.UI.Pager and open up Pager.cs.  Add this code right here:</p>
<pre class="brush: csharp; title: ; notranslate">
    /// &lt;summary&gt;
    /// Renders a pager component from an IPagination datasource, but pointing to a javascript function.
    /// &lt;/summary&gt;
    public class AjaxPager : Pager
    {
        public AjaxPager(IPagination pagination, HttpRequestBase request, string JSFunction, string Controller, string GridElement) : base(pagination,request)
		{
            _controller = Controller;
            _gridelement = GridElement;
            _functionname = JSFunction;
            _useAjax = true;
        }
    }
</pre>
<p>Next, you&#8217;ll need to add those protected variables to the base Pager class:</p>
<pre class="brush: csharp; title: ; notranslate">
        protected string _controller;
        protected string _gridelement;
        protected string _functionname;
        protected bool _useAjax = false;
</pre>
<p>Afterwards, modify the CreatePageLink() function to render a javascript link instead of a controller action link:</p>
<pre class="brush: csharp; title: ; notranslate">
private string CreatePageLink(int pageNumber, string text)
{
    if (_useAjax)
    {
        return string.Format(&quot;&lt;a href=\&quot;javascript:{0}('{1}','{2}',null,'{3}')\&quot;&gt;{4}&lt;/a&gt;&quot;, _functionname, _gridelement, _controller, pageNumber, text);
    }
    else
    {
        string queryString = CreateQueryString(_request.QueryString);
        string filePath = _request.FilePath;
        return string.Format(&quot;&lt;a href=\&quot;{0}?{1}={2}{3}\&quot;&gt;{4}&lt;/a&gt;&quot;, filePath, _pageQueryName, pageNumber, queryString, text);
    }
}
</pre>
<p>We now have an active pager component, but no pager extension methods that our HtmlHelper can utilize.  To remedy this, open up PagerExtensions.cs, and towards the bottom (right above or below the Pager implementation, for instance), enter this:</p>
<pre class="brush: csharp; title: ; notranslate">
public static Pager AjaxPager(this HtmlHelper helper, IPagination pagination, string JSFunction, string Controller, string GridElement)
{
    return new AjaxPager(pagination, helper.ViewContext.HttpContext.Request, JSFunction, Controller, GridElement);
}
</pre>
<p>Add tests if you would like, and recompile MvcContrib.dll.  Update your reference or recompile your project to do it automatically, and you should now have access to the .AjaxPager extension method.  Use it like so:</p>
<pre class="brush: csharp; title: ; notranslate">
&lt;%=Html.AjaxPager(ViewData[&quot;peeps&quot;],&quot;UpdateGrid&quot;,ViewData[&quot;controller&quot;],ViewData[&quot;griddiv&quot;])%&gt;
</pre>
<p>Finally, to get this whole process started, include the following function on your view:</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;
    $(document).ready(function() {
	UpdateGrid(&quot;#awesome_grid&quot;,&quot;/Home/Sort&quot;, &quot;FirstName&quot;);
    });
&lt;/script&gt;
</pre>
<p>This function gets the grid&#8217;s parent element and controller action persisted, along with its default sort column.  If you had multiple grids, you would have multiple calls to UpdateGrid, and they could each have their own target, action, and default sort column.</p>
<p>And that&#8217;s it!  It was quite a journey, but by cleverly extending where we can, and utilizing the proper accelerator libraries, we can achieve a sortable, pageable, AJAX-based grid that does most of its processing on your big iron, i.e. your DB or application servers, and minimizes the amount of bandwidth and client processing power needed.</p>
<p>Ideally, I would like to have a library that extended MvcContrib itself, since MvcContrib is under active development.  Extending the Pager and Grid helper methods without modifying the code would make them more future-proof.  Also, I&#8217;m going to work on making a sample project available so that folks can see how everything&#8217;s put together.</p>
<p>Summary:  One of the biggest challenges of a web-based business application developer involves presenting data to the user in a fast, useable fashion.  Sortable, pageable grids solve this dilemma by introducing the arduous process of creating the grids in the first place.  Leveraging and extending MvcContrib and jQuery to provide fast, asynchronous updates (from data sorted and paged on the server) to the user is a win.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fnathanielengelsen.com%2F2009%2F07%2Fadding-ajax-based-server-side-paging-and-sorting-to-mvccontrib-grid-using-jquery%2F&amp;partner=sociable" title="Print"><img src="http://nathanielengelsen.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fnathanielengelsen.com%2F2009%2F07%2Fadding-ajax-based-server-side-paging-and-sorting-to-mvccontrib-grid-using-jquery%2F&amp;title=Adding%20AJAX-based%20server-side%20paging%20and%20sorting%20to%20MvcContrib%20Grid%20using%20jQuery&amp;bodytext=One%20of%20the%20biggest%20challenges%20of%20a%20web-based%20business%20application%20developer%20involves%20presenting%20data%20to%20the%20user%20in%20a%20fast%2C%20useable%20fashion.%20%20Sortable%2C%20pageable%20grids%20solve%20this%20dilemma%20by%20introducing%20the%20arduous%20process%20of%20creating%20them.%20%20Leveraging%20and%20extending%20MvcContrib%20and%20jQuery%20to%20provide%20fast%2C%20asynchronous%20updates%20%28from%20data%20sorted%20and%20paged%20on%20the%20server%29%20to%20the%20user%20is%20a%20win." title="Digg"><img src="http://nathanielengelsen.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fnathanielengelsen.com%2F2009%2F07%2Fadding-ajax-based-server-side-paging-and-sorting-to-mvccontrib-grid-using-jquery%2F&amp;title=Adding%20AJAX-based%20server-side%20paging%20and%20sorting%20to%20MvcContrib%20Grid%20using%20jQuery&amp;notes=One%20of%20the%20biggest%20challenges%20of%20a%20web-based%20business%20application%20developer%20involves%20presenting%20data%20to%20the%20user%20in%20a%20fast%2C%20useable%20fashion.%20%20Sortable%2C%20pageable%20grids%20solve%20this%20dilemma%20by%20introducing%20the%20arduous%20process%20of%20creating%20them.%20%20Leveraging%20and%20extending%20MvcContrib%20and%20jQuery%20to%20provide%20fast%2C%20asynchronous%20updates%20%28from%20data%20sorted%20and%20paged%20on%20the%20server%29%20to%20the%20user%20is%20a%20win." title="del.icio.us"><img src="http://nathanielengelsen.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fnathanielengelsen.com%2F2009%2F07%2Fadding-ajax-based-server-side-paging-and-sorting-to-mvccontrib-grid-using-jquery%2F&amp;t=Adding%20AJAX-based%20server-side%20paging%20and%20sorting%20to%20MvcContrib%20Grid%20using%20jQuery" title="Facebook"><img src="http://nathanielengelsen.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fnathanielengelsen.com%2F2009%2F07%2Fadding-ajax-based-server-side-paging-and-sorting-to-mvccontrib-grid-using-jquery%2F&amp;title=Adding%20AJAX-based%20server-side%20paging%20and%20sorting%20to%20MvcContrib%20Grid%20using%20jQuery&amp;annotation=One%20of%20the%20biggest%20challenges%20of%20a%20web-based%20business%20application%20developer%20involves%20presenting%20data%20to%20the%20user%20in%20a%20fast%2C%20useable%20fashion.%20%20Sortable%2C%20pageable%20grids%20solve%20this%20dilemma%20by%20introducing%20the%20arduous%20process%20of%20creating%20them.%20%20Leveraging%20and%20extending%20MvcContrib%20and%20jQuery%20to%20provide%20fast%2C%20asynchronous%20updates%20%28from%20data%20sorted%20and%20paged%20on%20the%20server%29%20to%20the%20user%20is%20a%20win." title="Google Bookmarks"><img src="http://nathanielengelsen.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.dotnetkicks.com/kick/?url=http%3A%2F%2Fnathanielengelsen.com%2F2009%2F07%2Fadding-ajax-based-server-side-paging-and-sorting-to-mvccontrib-grid-using-jquery%2F&amp;title=Adding%20AJAX-based%20server-side%20paging%20and%20sorting%20to%20MvcContrib%20Grid%20using%20jQuery" title="DotNetKicks"><img src="http://nathanielengelsen.com/wp-content/plugins/sociable/images/dotnetkicks.png" title="DotNetKicks" alt="DotNetKicks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Fnathanielengelsen.com%2F2009%2F07%2Fadding-ajax-based-server-side-paging-and-sorting-to-mvccontrib-grid-using-jquery%2F&amp;t=Adding%20AJAX-based%20server-side%20paging%20and%20sorting%20to%20MvcContrib%20Grid%20using%20jQuery" title="HackerNews"><img src="http://nathanielengelsen.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fnathanielengelsen.com%2F2009%2F07%2Fadding-ajax-based-server-side-paging-and-sorting-to-mvccontrib-grid-using-jquery%2F&amp;title=Adding%20AJAX-based%20server-side%20paging%20and%20sorting%20to%20MvcContrib%20Grid%20using%20jQuery&amp;source=Nathaniel+Engelsen+&amp;summary=One%20of%20the%20biggest%20challenges%20of%20a%20web-based%20business%20application%20developer%20involves%20presenting%20data%20to%20the%20user%20in%20a%20fast%2C%20useable%20fashion.%20%20Sortable%2C%20pageable%20grids%20solve%20this%20dilemma%20by%20introducing%20the%20arduous%20process%20of%20creating%20them.%20%20Leveraging%20and%20extending%20MvcContrib%20and%20jQuery%20to%20provide%20fast%2C%20asynchronous%20updates%20%28from%20data%20sorted%20and%20paged%20on%20the%20server%29%20to%20the%20user%20is%20a%20win." title="LinkedIn"><img src="http://nathanielengelsen.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fnathanielengelsen.com%2F2009%2F07%2Fadding-ajax-based-server-side-paging-and-sorting-to-mvccontrib-grid-using-jquery%2F&amp;title=Adding%20AJAX-based%20server-side%20paging%20and%20sorting%20to%20MvcContrib%20Grid%20using%20jQuery" title="Reddit"><img src="http://nathanielengelsen.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=Adding%20AJAX-based%20server-side%20paging%20and%20sorting%20to%20MvcContrib%20Grid%20using%20jQuery&amp;url=http%3A%2F%2Fnathanielengelsen.com%2F2009%2F07%2Fadding-ajax-based-server-side-paging-and-sorting-to-mvccontrib-grid-using-jquery%2F" title="Slashdot"><img src="http://nathanielengelsen.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://nathanielengelsen.com/2009/07/adding-ajax-based-server-side-paging-and-sorting-to-mvccontrib-grid-using-jquery/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

