This is a migrated thread and some comments may be shown as answers.

[Solved] Sorting items in a panel

3 Answers 172 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jim
Top achievements
Rank 1
Jim asked on 19 Jan 2010, 12:13 AM
If a panel has been populated from an xml file, is it possible to sort the items in the panel?

3 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 19 Jan 2010, 09:25 AM
Hello Jim,

To achieve your goal you will need to use ToComponent() method, which will return the PanelBar object.
Thus you will be able to sort them, before render.

Here is an example how to use it in the view:
<% var builder = Html.Telerik().PanelBar()
                               .Name("PanelBar1")
                               .BindTo("SiteMap");
    
   var panelBar = builder.ToComponent();
 
   panelBar.Items.OrderBy(item => item.Text);
 
   builder.Render();
%>

Greetings,
Georgi Krustev
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.
0
Jim
Top achievements
Rank 1
answered on 19 Jan 2010, 04:02 PM
Thank you,
I understand that this will sort the PanelBar items, but I wish to sort the subItems within an individual panel.

Thanks,

Jim
0
Atanas Korchev
Telerik team
answered on 20 Jan 2010, 12:03 PM
Hi Jim,

You can use the following approach to sort all items:

<script runat="server">
    public void SortItems(INavigationItemContainer<PanelBarItem> owner)
    {
        IList<PanelBarItem> sortedItems = owner.Items.OrderBy(item => item.Text).ToList();
        owner.Items.Clear();
 
        foreach (PanelBarItem item in sortedItems)
        {
            SortItems(item);
            owner.Items.Add(item);
        }
    }
     
</script>
<%var panelbar = Html.Telerik().PanelBar()
        .Name("PanelBar")
        .HtmlAttributes(new { style = "width: 300px;" })
        .BindTo(Model, mappings =>
        {
            mappings.For<Category>(binding => binding
                    .ItemDataBound((item, category) =>
                    {
                        item.Text = category.CategoryName;
                    })
                    .Children(category => category.Products));
            mappings.For<Product>(binding => binding
                    .ItemDataBound((item, product) =>
                    {
                        item.Text = product.ProductName;
                    }));
        }).ToComponent();
 
    SortItems(panelbar);
 
    panelbar.Render();
%>

Sincerely yours,
Atanas Korchev
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.
Tags
PanelBar
Asked by
Jim
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Jim
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or