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.
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityView 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.