Webpart's Summary Toolbar view in list definition

I created a list from a custom list definition, and wanted to add the list as a webpart to a page defined in my custom site definition.

In the sitedefinition, it was enough to declare the BaseViewID property to define which view I wanted the list to display on the webpart.

<View List="Lists/LinksDocLibs" BaseViewID="4" WebPartZoneID="Left" WebPartOrder="2" />

Then, in the list definition, I modified my selected view to show the FreeForm toolbar, which should only display the "Add new item" link underneath the webpart.

<Toolbar Type="FreeForm" Position="After" />

However, when using this, the "Add new item" link is not shown. To accomplish this, we have to insert some HTML into the <Toolbar> tag. Do it like this:

<Toolbar Type="FreeForm" Position="After">

  <IfHasRights>

    <RightsChoices>

      <RightsGroup PermAddListItems="required"/>

    </RightsChoices>

    <Then>

      <HTML>

        <![CDATA[<table width=100% cellpadding="0" cellspacing="0" border="0">

        <tr><td colspan="2" class="ms-partline"><img src="/_layouts/images/blank.gif" width="1" height="1" alt=""></td></tr>

        <tr><td class="ms-addnew" style="padding-bottom:3px"><img src="/layouts/images/rect.gif" alt="">

        &nbsp;<a class="ms-addnew" ID="idAddNewItem" href="]]>

      </HTML>

      <URL Cmd="New"/>

      <HTML>

        <![CDATA[" onclick="NewItem(']]>

      </HTML>

      <URL Cmd="New"/>

      <HTML>

        <![CDATA[',true);return false;" target="_self">]]>

      </HTML>

      <HTML>

        Add a new item

      </HTML>

      <HTML>

        <![CDATA[</a></td></tr><tr><td><IMG src="/_layouts/images/blank.gif" width=1 height=5 alt=""></td></tr></table>]]>

      </HTML>

    </Then>

  </IfHasRights>

</Toolbar>

There, that should do the trick :)

Starting with this, you can also easily customize your layout as you can change the entire HTML markup for the Toolbar template ;)

Have fun with it ;)

 

Thanks to Tippu for the inspiration in this post.

Leave a Reply