Welcome close

We've made some changes!

As you may have noticed, we've made some changes to the DevCenter to include the new Exchange site, a code community for Ektron developers. You may use the same username and password to login for both the Exchange and DevCenter. Your DevCenter profile has moved over to the Exchange site. You also may notice we have removed some profile functionality in favor of new functionality, including Activity Streams. We welcome your feedback about the site on the Exchange forum.

SEARCH : searchSite
This SectionSite Wide
Version 8 

RSS Feed Print Category View
How-To: Create custom list sorting and have paging working
Rui @ Ektron
Posted: Friday, January 29, 2010 9:38 AM
Joined: 10/2/2006
Posts: 325


When you use a list control (ex: ListSummary, Collection, webSearch, ProductList), sorting based on a custom field (especially with Smart Form content, sorting based on a XPath) and have paging working together is always a challenge. Because once you enable paging, the paging process will happen before the sort. So the list on each page is sorted, but not over all. Even when you try to do the sorting in the XSLT, it doesn't help.

 

I saw a lot of post asking about that. So until the day the Controls can be re-engineered to allow custom sorting and paging working together, here is something you can try.

 

I'm using Xml.Linq to handle the sorting and generate the sorted list. Then used jQuery to generate the paging.

 

This works well for smart form content and sort by XPath in the smart form.

 

        XmlDocument productXML = new XmlDocument();
        productXML.LoadXml(ListSummary1.XmlDoc.InnerXml);
        XmlNodeReader nodeReader = new XmlNodeReader(productXML);
        nodeReader.MoveToContent();
        XDocument pXML = XDocument.Load(nodeReader);

 

var qs = from c in pXML.Descendants("Content")

                         orderby c.Element("Html").Element("root").Element("Location").Value ascending
                         select new
                         {
                             title = c.Element("Title").Value,
                             location = c.Element("Html").Element("root").Element("Location").Value,
                             href = c.Element("QuickLink").Value,
                         };
                foreach (var q in qs)
                    pages += "<p>" + q.location + " - <a href=\"" + q.href + "\">" + q.title + "</a></p>";

 

In the code, orderby c.Element("Html").Element("root").Element("Location").Value ascending allow you to dig down into the XML generated by the listing controls.

 

Attached is the sample page which display smart form content I created, you will need to modify the XPath to yours.

Any comments about making this code better is welcome /WorkArea/threadeddisc/emoticons/happy.png

 

 

 


 

Think outside the box.
Ektron CMS Smart Form XSLT = Great Design Idea w. Control


File Attachment(s):
customListPaging.zip (2555 bytes)
customSortPaging.jpg (65385 bytes)

eGandalf
Posted: Friday, January 29, 2010 10:04 AM
Joined: 9/13/2006
Posts: 2367


Nice work Rui! Thanks for posting.



http://www.ektron.com/services/


EktronJ
Posted: Friday, June 4, 2010 9:17 AM
Joined: 6/12/2006
Posts: 77


This code should ONLY be utilized if:

1) your data being retrieved is cached or cachable

2) you are dealing with records sub 100

This should not be used for paginating through search results, it is a major performance hit.

The proper way to do pagination with our search APIs is to set the Paging  Pagesize and Currentpage properties so that the server does the pagination.

All of the new Criteria filters on the Framework API take in PagingInfo for this reason.

Imagine if you had 500,000 search results.  Using this XSLT, you would have to load all 500,000 results and its data, and then sort through it.

Using the Pagination ability, the server is only returning you the data the size PageSize usually around 10, and then giving you the Page Count so you can build the proper pagination output.  If you want to switch to Page 2, just change the current Page via querystring or postback... re-initiating a server side query.  Our Search APIs will properly sort, and then give you back the current Page.  It does not re-sort the current page.  It re-sorts all of the data, and then returns the correct page.

Use the above code with Caution please.


 

Jump to different Forum... 






Register for Synergy 2010

Articles
Design without Borders, yet with Structure
CMS400.NET and Adobe Flex
GeoMapping
EkML Ektron Markup Language
Taxonomy

[First] [Previous] [Next] [Last]


See All Articles