1

How to add a custom button to allitems view of a custom list ?

Its just a list, and with only 1 view, i want to add a custom button on the view, which will navigate user to another page.

1 Answer 1

1

View pages are just web part pages.

You can edit the page add a button using a Content Editor Web Part above the list web part.

Edit:

This may be the way to go. Looks like you can add javascript to the page. With javascript you can render anything.

Edit2:

You can declare a view within a List Definition with the following markup

<View BaseViewID="2" 
      Name="8d2719f3-c3c3-415b-989d-33840d8e2ddb" 
      DisplayName="Overridable" 
      Type="HTML" 
      WebPartZoneID="Main" 
      SetupPath="pages\viewpage.aspx" 
      Url="Overridable.aspx"
      DefaultView="TRUE">
  <ViewFields>
    <FieldRef Name="Title" />
  </ViewFields>
  <Query />
  <Toolbar Type="Standard" />
  <XslLink>main.xsl</XslLink>
  <JSLink Default="TRUE">~site/Scripts/ButtonRender.js</JSLink>
</View>

Notice the JSLink attribute at the bottom.

Create the corresponding javascript file.

In the JS, the header template can be customized, which is one option for adding a button.

(function () {
    // Initialize the variable that stores the objects.
    var overrideCtx = {};
    overrideCtx.Templates = {};

    overrideCtx.Templates.Header = "<div><button>Test Button</button><br /><#=ctx.ListTitle#>";

    // Set the template to the:
    //  Custom list definition ID
    //  Base view ID
    overrideCtx.BaseViewID = 2;
    overrideCtx.ListTemplateType = 10057;

    // Register the template overrides.
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();

EDIT3:

The default header can be maintained by using this changing the header definition line to (Source):

overrideCtx.Templates.Header = "<div><button>Test Button</button><br /><#=ctx.ListTitle#>" + RenderTableHeader(overrideCtx) + "</table>";

As noted in the linked post, the RenderTableHeader method prints the default table, but doesn't print the table close(Maybe?).

I have not tested this as I don't have a 2013 env in front of me, but this should get you close.

6
  • thank you, but I want to do it in visual studio with list defintion Aug 14, 2014 at 12:34
  • Please add more details to your answer to make it less dependent in the links. E.g. outline the steps needed Aug 14, 2014 at 12:52
  • datasheet view is not visible anymore pleazo pleazo helpo Aug 14, 2014 at 15:47
  • I assume you mean the edit button is gone (as well as the rest of the header?) Aug 15, 2014 at 12:39
  • Just wondering. It isn't easier to use a module instead? Aug 15, 2014 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.