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

How to move items of the panelBar

9 Answers 139 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
aspUser
Top achievements
Rank 1
aspUser asked on 30 Jun 2011, 02:04 PM
Hello!

Please, can you tell me: how can i move 1-level items of the panelBar, when one of them was clicked?
For example:
panelBar:
item 1
item 2
item 3
When i click on the item, for example, "item 2", i want the result:
item 1
item 3
item 2
Note: this result i want get without postback, but after postback this result must be (perhaps, must use trackChanges-commitChanges).

Thank you.

9 Answers, 1 is accepted

Sort by
0
Nikolay Tsenkov
Telerik team
answered on 30 Jun 2011, 05:28 PM
Hi Aspuser,

You can handle the ClientItemClicked event and get the clicked item (args.get_item()) and then to insert the item in the next/previous position in the items collection (root.get_items().insert(index, item)).


Regards,
Nikolay Tsenkov
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
aspUser
Top achievements
Rank 1
answered on 01 Jul 2011, 11:40 AM
Hello, Nikolay. Thank you for your reply!
Earlier i have tried the strategy, which you have described. It have a problem.
Here is my code of the method, which handle "OnClientItemClicked" event of the panelBar:
        
onItemClicked = function(sender, eventArgs)
{
    var panelBar = $find("<%= rPanelBarMenu.ClientID %>");
    var itemsPanelBar = panelBar.get_items();
    var selectedItem = eventArgs.get_item();
    if (selectedItem.get_index() == itemsPanelBar.get_count() - 1) {
        return;
    }      
    panelBar.trackChanges();
    // insert selected item in the end of collection
    panelBar.get_items().insert(itemsPanelBar.get_count(), selectedItem); // this is problem string!!!
    // delete selected item with the old index
    panelBar.get_items().removeAt(selectedItem.get_index());
    panelBar.commitChanges();
};
        When i try to build project i have error window with this description:    
        "Microsoft JScript runtime error: 'this._element' -  is null or not an object".
        
        Please, help me to solve this problem.
        Thank you.
0
aspUser
Top achievements
Rank 1
answered on 06 Jul 2011, 06:36 AM
Hi!
Does anybody have any ideas about the topic?
0
Nikolay Tsenkov
Telerik team
answered on 06 Jul 2011, 08:12 AM
Hi Aspuser,

You shouldn't remove the item from it's previous place. It should be automatically moved.
Also the error you get, probably happens in run-time, since the JavaScript is not really syntactically checked server-side.


Regards,
Nikolay Tsenkov
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Ryan
Top achievements
Rank 1
answered on 14 Jul 2011, 05:45 PM
Hello,
I'm trying to do the same thing from the server side.  I want the user to be able to define the order of the panel bar items.  My panel bar items are declared/built on the .aspx page, but I need to reorder them from the code-behind (I'm assuming this would happen in Page_Init).  Is this possible?

Thanks,
Ryan
0
Ryan
Top achievements
Rank 1
answered on 14 Jul 2011, 05:52 PM
I'd like to add that I only want to set the order of the items when the page is loaded.  I'm not trying to do this with AJAX or on a postback.  The order of the items is defined on a separate page.
0
Nikolay Tsenkov
Telerik team
answered on 19 Jul 2011, 11:30 AM
Hello Ryan,

It most definitely is possible.
Could you, please, share what exactly seems to be the problem achieving it?
You probably handle the ItemClick server event?


Regards,
Nikolay Tsenkov
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Ryan
Top achievements
Rank 1
answered on 19 Jul 2011, 12:33 PM
I was wanting to order them on initial page load, not after any event.  Let's say you built the items in this order on the .aspx page:

Item 1
Item 2
Item 3

Let's say you defined your preferred order (on another page completely separate from this) as

Item 3
Item 2
Item 1

I wanted to be able to order the items in the code behind (on initial page load) to reflect the preferred order, even though they are declared in a different order on the .aspx page.  Unfortunately, you can't simply change the index of the items to move them around, you get errors.  I've solved my issue by building the items in the code behind in the proper order instead of declaring them on the .aspx page.
0
Nikolay Tsenkov
Telerik team
answered on 22 Jul 2011, 08:16 AM
Hi Ryan,

If we assume you have a list with the texts of the items (or if not unique - the values), you can foreach the list and find the item using the appropriate "FindBy..."-method and insert it (itemsCollection.Insert) in the correct position in the collection.

Regards,
Nikolay Tsenkov
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
PanelBar
Asked by
aspUser
Top achievements
Rank 1
Answers by
Nikolay Tsenkov
Telerik team
aspUser
Top achievements
Rank 1
Ryan
Top achievements
Rank 1
Share this question
or