Sort any EntityCollection with only a field name string?

Posts   
 
    
alexdresko
User
Posts: 336
Joined: 08-Jun-2004
# Posted on: 08-Jun-2004 18:51:06   

I am trying to create a custom DataGrid with built in support for sorting when combined with an EntityCollection as the DataSource.

My question is: Is it possible to sort a collection on a field if all you have is a field name?

Creating a SortExpression, from what I have been able to find, requires that you an pass <EntityName>FieldIndex. The problem is, the DataGrid doesn't know what concrete implementation of EntityBase is being used and there is no generic SortClauseFactory.Create(int fieldIndex,....) function. For example, the following line wouldn't work.


PrepareCollection(EntityCollectionBase collection, string fieldName)
{
   SortClause sorter = SortClauseFactory.Create(collection[0].Fields[fieldName].FieldIndex, (sortASC ) ? SortOperator.Descending : SortOperator.Ascending); 
}

That is as simple as I can try to explain it. I hope someone will be able to help me.

alexdresko
User
Posts: 336
Joined: 08-Jun-2004
# Posted on: 08-Jun-2004 22:15:55   

Hrmmm.. I really thought someone would reply to this by now. Seemed like the kind of thing where someone would post some blatantly obvious code that I hadn't thought about...

Still can't figure this one out.

Posts: 46
Joined: 07-Jan-2004
# Posted on: 08-Jun-2004 22:28:05   

alexdresko wrote:

Hrmmm.. I really thought someone would reply to this by now. Seemed like the kind of thing where someone would post some blatantly obvious code that I hadn't thought about...

Still can't figure this one out.

The sorting routines are for sorting the output as it comes from the database. I do not think there is in-memory or in collection sorting at this time.

You could of course roll your own and return the answer in another collection.

John

alexdresko
User
Posts: 336
Joined: 08-Jun-2004
# Posted on: 09-Jun-2004 03:45:11   

John wrote:

alexdresko wrote:

Hrmmm.. I really thought someone would reply to this by now. Seemed like the kind of thing where someone would post some blatantly obvious code that I hadn't thought about...

Still can't figure this one out.

The sorting routines are for sorting the output as it comes from the database. I do not think there is in-memory or in collection sorting at this time.

You could of course roll your own and return the answer in another collection.

John

Actually, I'm not doing anything llblgen can't do except specify a string for a sort column instead of an _ EntityName_FieldIndex. The most frustrating thing is that _ EntityName_FieldIndex is just an enum that returns an int anyway.. So why can't I just specify the index manually?

alexdresko
User
Posts: 336
Joined: 08-Jun-2004
# Posted on: 09-Jun-2004 03:47:37   

alexdresko wrote:

Actually, I'm not doing anything llblgen can't do except specify a string for a sort column instead of an _ EntityName_FieldIndex. The most frustrating thing is that _ EntityName_FieldIndex is just an enum that returns an int anyway.. So why can't I just specify the index manually?

BTW, as far as I can tell, the only problem with allowing the developer to specify their own int is a bounds checking issue if a field position is specified that doesn't exist.

Not a big deal if you ask me for the added functionality.

free4all
User
Posts: 35
Joined: 12-Sep-2003
# Posted on: 10-Jun-2004 12:46:03   

You can convert from a field name string into the field index enum:


C#:
<entityname>FieldIndex mySortField = (<entityname>FieldIndex)Enum.Parse(typeof(<entityname>FieldIndex), "mysortfield", true);

Just replace <entityname> with the name of the entity your working with and "mysortfield" can be any string matching a fieldname.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39752
Joined: 17-Aug-2003
# Posted on: 10-Jun-2004 13:25:57   

alexdresko wrote:

Hrmmm.. I really thought someone would reply to this by now. Seemed like the kind of thing where someone would post some blatantly obvious code that I hadn't thought about...

Still can't figure this one out.

I've send you an email with a reply on your question on Tuesday. Did you receive it or was it eaten by a spamfilter or something?

Frans Bouma | Lead developer LLBLGen Pro
alexdresko
User
Posts: 336
Joined: 08-Jun-2004
# Posted on: 10-Jun-2004 15:33:07   

Otis wrote:

alexdresko wrote:

Hrmmm.. I really thought someone would reply to this by now. Seemed like the kind of thing where someone would post some blatantly obvious code that I hadn't thought about...

Still can't figure this one out.

I've send you an email with a reply on your question on Tuesday. Did you receive it or was it eaten by a spamfilter or something?

I got it. I still have to figure out how to do implement your suggestion, I just haven't had time yet. Thanks though!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39752
Joined: 17-Aug-2003
# Posted on: 10-Jun-2004 15:46:42   

Ok smile

Frans Bouma | Lead developer LLBLGen Pro