Welcome to the CodeSmith Community!

Re: NetTiers2 CTP: Dynamic List Sorting

.netTiers

A description has not yet been added to this group.

NetTiers2 CTP: Dynamic List Sorting

  • rated by 0 users
  • This post has 10 Replies |
  • 3 Followers
  • http://www.codeproject.com/dotnet/dynamiclistsorting.asp

    What do you think about using such way for sorting?

    Can anybody provide sample of using current Sort
    method for TList entities?

    Thanks.
    Best regards,
    Alex.
  • Alex,

    I have included a sample below of sorting using TList.  It's not as clean as I think that it could be, but it' just using the base interfaces.  I don't know why we couldn't provide an overload of ApplySort that would allow the Order By syntax.  It's just a matter of implementing it.  I would like to spend some time looking at the article you mentioned to look at their implementation of the Comparer class.

     

    TList<CIRStatus> list = DataRepository.CIRStatusProvider.GetAll();

    PropertyDescriptorCollection propColl = TypeDescriptor.GetProperties(typeof(CIRStatus));

    //Simple Sort

    list.ApplySort(propColl["CIRStatusID"], ListSortDirection.Descending);

    //Complex Sort

    ListSortDescription[] sortDescs = new ListSortDescription[2];

    sortDescs[0] = new ListSortDescription(propColl["CIRStatusDescription"],ListSortDirection.Ascending);

    sortDescs[1] = new ListSortDescription(propColl["CIRStatusID"], ListSortDirection.Ascending);

    list.ApplySort(new ListSortDescriptionCollection(sortDescs));

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

  • Thanks a lot for response, Ben! I'm still can't decide how to work with GridView and support all features of it like sorting, paging and so on. The key problem, because this is not possible at present simply write custom stored procedure based on view and use strongly typed ObjectDataSource, because at present view class is based on Generic.List :-/ I've found that it's better to use custom stored procedure as DataSet for table class, because in this case sorting and paging and filtering can be used without problems. But in this case there is no nice strongly typed databinding and so on :( May be strongly typed dataset can be best option for such cases? I've looked into Web Admin for ASP.NET 2.0 and found many useful things I was looking to implement, but also found that you use GetPaged method and get foreign keys fields ~ IDSource for every row and this is not the best option for production applications... Looks like building strongly typed DataSet directly using VS 2005 is the best options at present for GridView databinding :(
    Best regards,
    Alex.
  • Guys, DynamicSorter can be good option or just made the following small fix, please: #region Sort Comparer public class SortComparer : IComparer Thanks.
    Best regards,
    Alex.
  • Alex,

    So, you would like SortComparer to implement the IComparer interface?  Is this in addition to the IComparer<T>, which it already implements?  If so, have you already done this?  Also, why is this interface needed?  Any shared code would be appreciated.

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

  • Hi, Ben. You did not get me. I was talking about just making SortCompare as public to be able to use it for views classes and pass it to sort like you showed in example. Actually I think that replacing SortComparer by DynamicCompare (http://www.codeproject.com/dotnet/dynamiclistsorting.asp) would be the best option because it already has the following method: public void Initialize(string orderBy) and it can be used directly for sorting purposes for GridView...
    Best regards,
    Alex.
  • Alex,

    Yep, I misunderstood what you were asking.  It makes much more sense now.  I missed the "public" part...  Oh well.... 

    I decided to stay with the SortComparer class, just because I understand how it works.  When I started looking at the DynamicSorter and saw that it emits IL code directly, I got a little itimidated (especially from a support standpoint if something doesn't work).  However, I went ahead and added the ability to pass in a SQL-like order by clause to TList and SortComparer.  Hopefully, it will give you the functionality you need.

    SortComparer:

    public SortComparer(string orderBy)

    TList:

    public void Sort(string orderBy)

    public void Sort(Comparison<T> comparison)

    public void Sort(IComparer<T> comparer)

    So, now you can do things like:

    TList<MyObject> list = DataRepository.MyObjectProvider.GetAll();

    list.Sort("Property1 desc, Property2 asc, Property3 desc");

    //OR

    SortComparer sortComparer = new SortComparer("Property2 desc");

    list.Sort(sortComparer);

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

  • Thanks, Ben, this is what I wanted! :)
    Best regards,
    Alex.
  • Ben,

    For nullable columns, CompareValues in TList.cst throws exception. Need to check null before calling value.ToString(). With that modification, all work well.

    Roy

  • Roy,

    Thanks, it should be fixed now.

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

  • Hi, Ben,

    I don't know how to use TList or VList Sort method working with a GridView (see my post http://community.codesmithtools.com/forums/thread/10139.aspx).  Could you provide more detailed information?  Forgive me if this is naive. 

    Thanks,
    Kangming

Page 1 of 1 (11 items)