locked
How to show ribbon for webpart by default? RRS feed

  • Question

  • Hello,

    We have a SharePoint list, and on the default view (AllItems.aspx) we added a content editor web part below the list to give some info about the icons we use in the list.

    Because of that, SharePoint is not able to display the Ribbon menu for the list by default. Instead we have to click in the list first, in order to see the ribbon menu.

    Is it possible (with jQuery or something) to display the ribbon menu for the list by default without having to click in the list first?

    Thanks in advance!

    Thursday, January 5, 2012 10:48 AM

Answers

  • Ok after searching for hours I found this javascript code that does the trick.
    In our page we have put the cewp above list, and we have a total of 2 webparts on the page (the cewp and the list).

    ExecuteOrDelayUntilScriptLoaded(selectWP, "sp.ribbon.js");  
    
    function selectWP()
    {
    	/*
    	 * SELECT THE LIST WEB PART
    	 * THEN MAKE THE RIBBON APPEAR FOR THE LIST
    	 */
    	 
    	//get selected webpart
    	var wp = document.getElementById("_wpSelected");
    	if (wp != null)
    	{
    		//switch to second webpart (the list)
    		wp.value ="MSOZoneCell_WebPartWPQ2";
    		//call the ribbon for this webpart
    		SelectRibbonTab('Ribbon.Read', true)
    	}
    }
    

    You can find the value "MSOZoneCell_WebPartWPQ2" when viewing the rendered HTML code of the page.
    The second webpart in our case is wrapped in a td that has the id "MSOZoneCell_WebPartWPQ2".

    I hope this saves someone else the pain of digging into google results for hours...

    • Marked as answer by kurtvd Thursday, January 5, 2012 11:39 AM
    Thursday, January 5, 2012 11:39 AM