Multiple Column Sorting and Codus

Posted on April 30, 2005 04:22 by LeviRosol

To start, I need to thank Tim Gifford[^] for pointing out this article[^] in a recent issue of CoDe Magazine by J.Ambrose Little[^].

I've been working on a lite web framework for the NTeam Projects's site[^] for the last week or so, and am starting to get into the GUI of the site. Before I got to far along, I want to flesh out some of the base controls within the site. I was able to successfully implement FreeTextBox 3.0[^] with NetSpell[^] (great tool Paul[^]!) and wasted some time trying to setup a base grid control to use for some of my manager pages. I say 'wasted' because although Infragistics[^] looks uber sweet, it's less that easy to implement in a dynamic way. Either that, I was missing the obvious.

So after battling that for a couple days, I decided to go back to using a standard datagrid, something I'm used to using. I got my BaseControls.ManagerGrid class going, and built out a basic template to display a grid. Next thing wanted was sorting. Assuming someone else out in the WWW had already written what I was looking for, I spent some time on google looking for some code to utilize. First thing I came across looked very familiar. It was an article by Rocky Lhotka[^] on msdn where he created a SortedView object[^] that did most of the work for sorting. I knew this would work for me, however, it was in VB.Net, and I didn't want to recreate the wheel knowing someone else had to have done what I was looking for in C#.

Well, I was right! I recalled a conversation with Tim[^] where he mentioned an article that described how to do multi column sorting. Did a bit more google searching, and ended up here[^]. Longer story shorter, I ended up here[^] where I was able to download the source code for J. Ambrose's SortableCollectionBase[^] object. I then opened his demo project, compiled, and ran the nUnit tests. Worked perfectly!

The next challenge was integrating it with my DAL and/or BLL. My first stab was to add it to my BLL. That would have worked just fine, however, I found an even better way of making it accessible throughout the framework automatically. Here's how:

First, I added the SortableCollectionBase object to my  Codus[^] built DAL and updated the namespace. I then altered all of the auto generated EntityCollection objects so that they inherited from my new SortableCollectionBase object (find/replace worked well). That's all I needed to do to integrate J.Ambrose's[^] SortableCollectionBase into Codus[^]! Now for the fun part. Here is all you need to do to utilize it in this scenario:

1private void BindGridData(string SortBy)  2{  3    PageEntityCollection myCollection = new PageEntityCollection(Database.PageMapper.SelectAll());  4  5    myCollection.Sort("Name ASC,Path DESC");  6   7    this.MyManagerGrid.DataSource = myCollection;  8    this.MyManagerGrid.DataBind();  9}

There's certainly some refactoring that needs to take place here, however, I think I've conveyed the point. Not only is J. Ambrose[^] uber cool for building such a robust object, but Codus[^] is pretty darn extendable! Hopefully Sean McCormack[^] gets some time to read this blog, and evaluates adding this functionality to the auto generated code.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

November 21. 2008 14:43