November Happy Hour will be moved to Thursday December 5th.

Sort pages by two properties

Vote:
 

Hi!

I have a pagedatacollection... Right now im sorting this collection by "date" and then by "division" with FilterPropertySort... the following way:

new FilterPropertySort("Date", FilterSortDirection.Descending).Filter(KPages); 
new FilterPropertySort("Division").Filter(KPages); 

Somehow it seems like the later sorting is messing up the first sorting (in some cases)... The order by date is not fully maintained. I wonder if am doing this the wrong way maybe... How could/should I sort this collection in another way?

 

#76232
Oct 21, 2013 15:47
Vote:
 

How about if you use OrderBy() and ThenBy() LINQ extension methods?

Frederik

#76246
Oct 21, 2013 21:27
Vote:
 

Okey... I've had a look at LINQ now and I feel a bit confused (I haven't used LINQ before). I tried the following

var alist = from p in DataFactory.Instance.GetChildren(aPage)
orderby p.Property["Date"]
select p;

rptList.DataSource = alist; 
rptList.DataBind();

I run into problems with the datasource at runtime (Err: At least one object must implement IComparable.). I'm using a repeater to display my list. If you have some "for dummies" example that I can learn from it would be great :) Have done a bit of searching on the subject and the links tend to lead me to places where I don't belong atm ;)

#76326
Oct 22, 2013 10:04
Vote:
 

This error comes from the orderby statement and the p.Property["Date"]. If you trying to sort by publish date use that instead:

orderby p.StartPublish

Frederik    

#76327
Oct 22, 2013 10:09
Vote:
 

Your right! The thing is, I'm not trying to sort it by publishdate... I wanna sort it by a property (Date) that describes when something is happening (DateTime). It should be possible right?

#76329
Oct 22, 2013 10:49
Vote:
 

Yes, just cast it to DateTime.

orderby (DateTime)p.Property["Date"]

    

#76330
Oct 22, 2013 10:50
Vote:
 

Hmm... I tried that earlier but get "Cannot convert type EPiServer.CorePropertyData" to "System.DateTime". Thank you for your replies :) Any ideas?

#76331
Oct 22, 2013 10:55
Vote:
 
orderby (DateTime)p["Date"]

    

#76332
Oct 22, 2013 10:57
Vote:
 

YES! Awesome :) Many thanks Frederik... Good to know for future use. Hope you have a real nice day now :)

#76333
Oct 22, 2013 11:02
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.