Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Dataset child sorting View modes: 
User avatar
Member
Member
colin.campbell-designkitchen - 12/9/2009 4:16:49 PM
   
Dataset child sorting
I've got a question about sorting of child elements.

I have a complicated hierarchy of elements and I'm programatically building html through a string builder that gets set on an ASP Literal element.

I have the following code: (just one of the data set queries)

TreeNode treeNode = tree.SelectSingleNode((int)documentChildRow["NodeID"]);
DataSet children = tree.SelectNodes(CMSContext.CurrentSiteName, treeNode.NodeAliasPath + "/%",
treeNode.DocumentCulture, true, DOCUMENT_CHILD_TYPES, "NodeParentID = " + (int)treeNode.GetValue("NodeID"));

DOCUMENT_CHILD_TYPES is two different types of documents. After returning the the data set, I do a foreach through that dataset and add different html elements depending on the type. Yet when the elements are displayed on the page, it's never mixed.

So if the dataset returned is [Chapter,PDF,Chapter,PDF], it ends up displaying on the page as
Chapter
Chapter
PDF
PDF

instead of
Chapter
PDF
Chapter
PDF

even though that's how it appears in the CMS tree.

How do I control the sorting of Dataset elements? Isn't the default by NodeId (which corresponds to order of creation?) Can anyone please help me with this?

Thanks.

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 12/10/2009 4:16:51 AM
   
RE:Dataset child sorting
Hello,


you may use the overloaded SelectNodes method which involves the Order by expression.

The specification looks like:

public virtual DataSet SelectNodes(
string siteName,
string aliasPath,
string cultureCode,
bool combineWithDefaultCulture,
string classNames,
string where,
string orderBy
)

The API Reference is here: http://devnet.kentico.com/downloads/kenticocms_api.zip

Best regards,
Helena Grulichova

User avatar
Member
Member
colin - 12/10/2009 9:39:29 AM
   
RE:Dataset child sorting
Helena,

Thank you for your answer. I had already looked at the API and am using the overloaded method that uses the order by. The behavior I'm seeing is unmodified by using the order by clause. Here's the code with the order by clause included.


public const string DOCUMENT_CHILD_TYPES = "Custom.PDF" + ";" + "Custom.DocumentChapter";
int documentNode = (int)row["NodeID"];
DataSet documentChildren = tree.SelectNodes(CMSContext.CurrentSiteName, rootNode.NodeAliasPath + "/%",
rootNode.DocumentCulture, true, DOCUMENT_CHILD_TYPES,
"NodeParentID = " + documentNode, "NodeID");

Am I constructing the order by clause parameter incorrectly? The behavior that puzzles me is that the order seems to be dependent on the order in which I construct the classnames parameter.

Where I have the Custom.PDF first, PDFs show up before the Chapters. When I switch it so that Custom.DocumentChapter is first, all of the chapters show up first. Also, I should mention that I have set
tree.MergeResults = true; on my TreeProvider.

So is this a bug in the classnames parameter or am I making use of this method incorrectly?

Thanks in advance for your help.


User avatar
Member
Member
colin - 12/10/2009 11:29:03 AM
   
RE:Dataset child sorting
Ok, this is very curious. I was looking around and I've changed my code to order according to the positioning and order in the CMS tree. I'm still seeing that elements come back in the incorrect order however. Here is the corresponding code:

public const string DOCUMENT_CHILD_TYPES = "Custom.PDF" + ";" + "Custom.DocumentChapter";
int documentNode = (int)row["NodeID"];
DataSet documentChildren = tree.SelectNodes(CMSContext.CurrentSiteName, rootNode.NodeAliasPath + "/%",
rootNode.DocumentCulture, true, DOCUMENT_CHILD_TYPES,
"NodeParentID = " + documentNode, "NodeLevel, NodeOrder, NodeName");

I've debugged through this watching the values of documentChildren and while the order of the elements in the CMS tree is Chapter PDF Chapter, the dataset returns in PDF, Chapter, Chapter order. Is there some setting that I'm missing to correct this?

Thanks in advance!

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 12/11/2009 7:46:38 AM
   
RE:Dataset child sorting
Hello,

You are right it sorts results only for one document type.

If you need the global sorting you need to sort the dataset by standard ASP.NET methods - for eaxmple please see here: http://msdn.microsoft.com/en-us/library/1ay5y4w0(VS.71).aspx

I am sorry for confusing.

Best regards,
Helena Grulichova

User avatar
Member
Member
colin - 12/11/2009 9:20:49 AM
   
RE:Dataset child sorting
Helena,

Thanks again for your answer. I will use standard sorting methods if that is the case. It's really not clear in the documentation that this is the case. It would be very useful to update the documentation available on the Kentico CMS to be very clear that multiple document types cannot be sorted together inline according to the Node attributes in the CMS tree.

Thanks again for your help.
Colin

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 12/15/2009 7:28:10 AM
   
RE:Dataset child sorting
Hi Colin,

You are welcome.

We will write a FAQ or Knowledge base article about this issue. Thank you for your suggestion.

Best regards,
Helena Grulichova