Module Builder Code reference - Get Collection add Order by

Posted by Community Admin on 05-Aug-2018 05:27

Module Builder Code reference - Get Collection add Order by example line

All Replies

Posted by Community Admin on 22-Aug-2012 00:00

First of all - the module builder is great and the code reference such a huge help.

However I did as struggle to get an orderby working.

Original what the codereference shows.

// Demonstrates how a collection of Quicklinks can be retrieved
public IQueryable<DynamicContent> RetrieveCollectionOfQuicklinks()
    DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
    Type quicklinkType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Quicklinks.Quicklink");
    CreateQuicklinkItem(dynamicModuleManager, quicklinkType);
              
    // This is how we get the collection of Quicklink items
    var myCollection = dynamicModuleManager.GetDataItems(quicklinkType);
    // At this point myCollection contains the items from type quicklinkType
    return myCollection;

a) I think one line should be modified or you get double entries if I am not mistaken.

var myCollection = dynamicModuleManager.GetDataItems(quicklinkType).Where(item => item.Status == ContentLifecycleStatus.Live)

b) I did try to have some stuff sorted by a sort value I had added as integer. Dumb as I am I started with.

var myCollection = dynamicModuleManager.GetDataItems(quicklinkType).Where(item => item.Status == ContentLifecycleStatus.Live).OrderBy("Sortvalue"));

Then support thought it should be. Which led to an error

var myCollection = dynamicModuleManager.GetDataItems(quicklinkType).Where(item => item.Status == ContentLifecycleStatus.Live).OrderBy(i => i.GetValue("Sortvalue"));

CORRECT working was

adding ' using Telerik.OpenAccess' and modify the line to 

var myCollection = dynamicModuleManager.GetDataItems(quicklinkType).Where(item => item.Status == ContentLifecycleStatus.Live).OrderBy(i => i.FieldValue<decimal>("Sortvalue"));

So maybe the order by is a common task that could somehow be implemented as a examples string. Could be commented.

Thanks again for the support

Markus




This thread is closed