+1-888-365-2779
Try Now
More in this section

Lists module

25 posts, 0 answered
  1. Rabindra
    Rabindra avatar
    106 posts
    Registered:
    17 May 2009
    09 Nov 2009
    Link to this post
    I have created a list in which it has bunch of list items.
    How can sort this list items in client side (A-Z)?
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    09 Nov 2009
    Link to this post
    Hello Rabindra,

    This option is not implemented in the default control, but there is a solution to this issue. The default control has a CustomDataSource option. You can create a new datasource and set the control to use it. Please use the API to build a list of Lists that you require. 

    I have attached a screenshot showing the property of the ListDisplay control.

    All the best,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Rabindra
    Rabindra avatar
    106 posts
    Registered:
    17 May 2009
    09 Nov 2009
    Link to this post
    thank you for the reply but I couldn't find what to put in there.
    Whatever I type in there, nothing is saved.
    My list name is "Information Board" so what should I put in "customdatasource" to sort in in ascending order?

  4. Rabindra
    Rabindra avatar
    106 posts
    Registered:
    17 May 2009
    09 Nov 2009
    Link to this post
    the only info I found is in this link which isn't much help
    http://www.sitefinity.com/help/developer-manual/telerik.lists-telerik.lists.webcontrols.listdisplay-customdatasource.html


  5. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    09 Nov 2009
    Link to this post
    Hello Rabindra,

    I am going to show you:
    1. How to use the customdatasource property
    2. How to override the control to implement sorting

    Mind you that the obejct I use for the CustomDataSource is an IList, which can be provided on any other control on the page (if you do not want to override the default control).  Here's the code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Lists.WebControls;
    using System.Collections;
     
    /// <summary>
    /// Summary description for CustomListsDisplay
    /// </summary>
    public class CustomListsDisplay : ListDisplay
    {
        public CustomListsDisplay()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        protected override void CreateChildControls()
        {
            IList lists = base.Manager.GetListsByIds(base.ListsIds);
            //perform sorting on lists
            //there examples on internet on sorting IList objects
            //you can use comparer or implement custom sorting, then use the customdatasource:
     
            base.CustomDataSource = lists;
            base.CreateChildControls();
        }
        public override Type AssemblyInfo
        {
            get
            {
                return typeof(ListDisplay);
            }
            set
            {
                base.AssemblyInfo = value;
            }
        }
        public override Type LocalizationAssemblyInfo
        {
            get
            {
                return typeof(ListDisplay);
            }
            set
            {
                base.LocalizationAssemblyInfo = value;
            }
        }
    }


    Greetings,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Rabindra
    Rabindra avatar
    106 posts
    Registered:
    17 May 2009
    10 Nov 2009
    Link to this post
    hi Georgi,
      thank you for trying to help me out but i am totally lost.
    I don't know where to save the file? Do I save it in App_code folder? Then what's next?
    Also when I try to save anything in "CustomDataSoucce", nothing gets saved.

    pls help?
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Nov 2009
    Link to this post
    Hi Rabindra,

    This is a custom class that inherits from ListDisplay and you can add it to App_Code folder or compile it to dll.
    Under CreateChildcontrols method we are calling a custom IList.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. Rabindra
    Rabindra avatar
    106 posts
    Registered:
    17 May 2009
    10 Nov 2009
    Link to this post
    HI Ivan,
       If you look at the image Georgi  sent, when I try to save any text in "CustomDataSource", nothing is saved.
    Do you know why?
  9. Rabindra
    Rabindra avatar
    106 posts
    Registered:
    17 May 2009
    10 Nov 2009
    Link to this post
    Ok, I created "CustonLists.cs" in App_folder. Then what's next? How do I use this class?
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Nov 2009
    Link to this post
    Hi Rabindra,

    You need to register the control in your web.config and then drop it on your page.

    <toolboxControls>
     <clear />
               ....
                  ....
      <add name="CustomList" section="Custom" type="CustomList, App_Code"/>

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  11. Rabindra
    Rabindra avatar
    106 posts
    Registered:
    17 May 2009
    10 Nov 2009
    Link to this post
    I added that in web.config file.
    Now in Admin page, I get this error "Error loading control" with toltip "Could not load type "CustomLists" from assembly "App_Code""

  12. Rabindra
    Rabindra avatar
    106 posts
    Registered:
    17 May 2009
    11 Nov 2009
    Link to this post
    I finally got it to work partially.
    How do I sort list items of a list? This is what I have so far.
      Telerik.Lists.ListManager listManager = new Telerik.Lists.ListManager(); 
                IList allLists = listManager.GetLists("Name DESC"); 
                //perform sorting on lists 
                //there examples on internet on sorting IList objects 
                //you can use comparer or implement custom sorting, then use the customdatasource: 
     
                base.CustomDataSource = allLists

    How do I use comparer or  custom sorting?
  13. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    11 Nov 2009
    Link to this post
    Hi Rabindra,

    I have commented what you should use to sort the Lists. Please check the following articles:

    * Sorting Generic Lists with Comparer class - http://msdn.microsoft.com/en-us/library/234b841s.aspx

    This is not specific to Sitefinity, but rather to the general .NET. 

    Kind regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  14. Rabindra
    Rabindra avatar
    106 posts
    Registered:
    17 May 2009
    13 Nov 2009
    Link to this post
     I looked at the links you sent me and searched the web too but I couldn't
    sort the way I wanted.
    Anyone willing to help me on how to sort list items of a list?
  15. Rabindra
    Rabindra avatar
    106 posts
    Registered:
    17 May 2009
    17 Nov 2009
    Link to this post
    Hi Ivan and Georgi,
          On this code, you have comments on Perfom sorting on lists.
    protected override void CreateChildControls() 
        { 
            IList lists = base.Manager.GetListsByIds(base.ListsIds); 
            //perform sorting on lists 
            //there examples on internet on sorting IList objects 
            //you can use comparer or implement custom sorting, then use the customdatasource: 
      
            base.CustomDataSource = lists
            base.CreateChildControls(); 
        } 

    I didn't want to sort lists rather I wanted to sort all list items within a list. I only have one list item.
    Can you please, please provide me with some code? I really appreciate your help.
  16. Rabindra
    Rabindra avatar
    106 posts
    Registered:
    17 May 2009
    17 Nov 2009
    Link to this post
    I think I managed to sort list items in a list but there is a problem.
    While debugging, I found that even though the list items are sorted by "Headline", the end result is not sorted by "Headline" because of "Ordinal"

    Ordinal = Represents the position of the ListItem inside of a NamedList. The smaller the number the closer to the top of the list a ListItem is.

    Is it possible to programmatically overwrite or change "Ordinal" of each List Items?
  17. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Nov 2009
    Link to this post
    Hello Rabindra,

    You can use Linq to get the order of the list. Sample code:

    IQueryable<IListItem> dataSource = (((INamedList)e.Item.DataItem).Items).AsQueryable<IListItem>();
     
    // order by descending
    listItems.DataSource = dataSource.OrderByDescending(c => c.Ordinal);

    The number of Ordinal cannot be overridden. It is set in private class Items in for loop for IListItem object.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  18. Rabindra
    Rabindra avatar
    106 posts
    Registered:
    17 May 2009
    18 Nov 2009
    Link to this post
    How do I use this code along with the code posted by Georgi above?
    I get error under "e"
    Also, I don't want to sort by ordinal. I want to sort by Headline?
  19. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    18 Nov 2009
    Link to this post
    Hi Rabindra,

    Then call c.Headline which is a property of "c" object.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  20. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    23 Mar 2011
    Link to this post
    Hello Ivan

    I tried different things to sort the IList (IComparer, LINQ), but haven't succeed yet.
    You describe the following sort  procedure:

    IQueryable<IListItem> dataSource = (((INamedList)e.Item.DataItem).Items).AsQueryable<IListItem>();
       
    // order by descending
    listItems.DataSource = dataSource.OrderByDescending(c => c.Ordinal);

    But in the CreateChildControls function, the place where Iwant to sort the IList lists, you don't have the e.Item.DataItem param.
    Probably your procedure can be used in an eventhandler. But for what eventhandler did you define this?

    Regards
    Luc
  21. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    28 Mar 2011
    Link to this post
    Hello Luc,

    There is no data item in the CreateChildControls. You should subscribe/override for ItemDataBound event of the mode you use. For example

    PageLists_ItemDataBound where we call PageListItems_ItemDataBound event of the child repeater.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
  22. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    28 Mar 2011
    Link to this post
    Hello Ivan

    I added the code in the ExpandableLists_ItemDataBound eventhandler

    On statement

    IQueryable<IListItem> dataSource = (((INamedList)e.Item.DataItem).Items).AsQueryable<IListItem>();

    I get the error 'System.Collections.IList' does not contain a definition for 'AsQueryable' and the best extension method overload 'System.Linq.Queryable.AsQueryable<TElement>(System.Collections.Generic.IEnumerable<TElement>)' has some invalid arguments

    Any ideas?

    By the way is listItems in you code a reference to the repeater in the template?

    regards
    Luc
  23. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    31 Mar 2011
    Link to this post
    Hello,

    Try getting the list and then cast it to the type

    IList items = ((INamedList)e.Item.DataItem).Items;

    IQueryable<IListItem> itemsInQuery = items.Cast<IListItem>().AsQueryable<IListItem>();

    All the best,
    Ivan Dimitrov
    the Telerik team
  24. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    06 Apr 2011
    Link to this post
    Hello Ivan

    I am using this eventhandler

    protected override void ExpandableLists_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Repeater listItems = (Repeater)e.Item.FindControl("listItems"); 
        if (listItems != null)
        {
            IList items = ((INamedList)e.Item.DataItem).Items;
            IQueryable<IListItem> itemsInQuery = items.Cast<IListItem>().AsQueryable<IListItem>();
            var sortedItems = from item in itemsInQuery
                              orderby item.Headline ascending
                              select item; 
            listItems.DataSource = sortedItems.ToList();
        }
    }

    Probably I am overseeing something but it doesn't show the list items in the listItems repeater yet. Have you any idea?

    Kind regards
    Luc
  25. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    06 Apr 2011
    Link to this post
    Hello Ivan

    After taking a break and coming back to work further I saw what I had overseen: listItems.DataBind()

    This is the code that works fine now:

    protected override void CreateChildControls()
    {
        IList lists = base.Manager.GetListsByIds(base.ListsIds);
        //perform sorting on lists
        //there examples on internet on sorting IList objects
        //you can use comparer or implement custom sorting, then use the customdatasource:
        base.CustomDataSource = lists;
        base.CreateChildControls();
    }
    public override Type AssemblyInfo
    {
        get
        {
            return typeof(ListDisplay);
        }
        set
        {
            base.AssemblyInfo = value;
        }
    }
    public override Type LocalizationAssemblyInfo
    {
        get
        {
            return typeof(ListDisplay);
        }
        set
        {
            base.LocalizationAssemblyInfo = value;
        }
    }
    protected override void ExpandableLists_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Repeater listItems = (Repeater)e.Item.FindControl("listItems"); 
        listItems.ItemDataBound += new RepeaterItemEventHandler(listItems_ItemDataBound);
        if (listItems != null)
        {
            IList items = ((INamedList)e.Item.DataItem).Items;
            IQueryable<IListItem> itemsInQuery = items.Cast<IListItem>().AsQueryable<IListItem>();
            var sortedItems = from item in itemsInQuery
                              orderby item.Headline ascending
                              select item; 
            listItems.DataSource = sortedItems.ToList();
            listItems.DataBind();
        }
    }
    protected void listItems_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        //Fill the nested repeater items here
    }

    Thanks for your support
    regards
    Luc
Register for webinar
25 posts, 0 answered