Skip to content

Commit 1f121db

Browse files
authored
Linda editor 12 20 (SharePoint#1170)
* Final edit * Final edit * Final edit * Final edit * Final edit * Added breaks * Final edit * Final edit * Final edit - Widgets
1 parent bf4bc1e commit 1f121db

12 files changed

+968
-1527
lines changed

docs/sp-add-ins/create-add-in-parts-to-install-with-your-sharepoint-add-in.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ To follow the steps in this example, you need the following:
3636

3737
- Visual Studio
3838
- Microsoft Office Developer Tools for Visual Studio
39-
- A SharePoint development environment. If you need help setting up a development environment, see [Get started creating provider-hosted SharePoint Add-ins](get-started-creating-provider-hosted-sharepoint-add-ins.md).
39+
- A SharePoint development environment. If you need help setting up a development environment, see [Two types of SharePoint Add-ins: SharePoint-hosted and provider-hosted](sharepoint-add-ins.md#two-types-of-sharepoint-add-ins-sharepoint-hosted-and-provider-hosted).
4040

4141
<a name="SP15Createappparts_Codeexample"> </a>
4242

docs/sp-add-ins/create-custom-actions-to-deploy-with-sharepoint-add-ins.md

Lines changed: 204 additions & 261 deletions
Large diffs are not rendered by default.

docs/sp-add-ins/customize-a-list-view-in-sharepoint-add-ins-using-client-side-rendering.md

Lines changed: 108 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,26 @@
11
---
22
title: Customize a list view in SharePoint Add-ins using client-side rendering
3-
ms.date: 09/25/2017
3+
description: Customize a list view in a SharePoint-hosted add-in by using the client-side rendering technology in SharePoint.
4+
ms.date: 12/20/2017
45
ms.prod: sharepoint
56
---
67

78

89
# Customize a list view in SharePoint Add-ins using client-side rendering
9-
Learn how to customize a list view in a SharePoint-hosted add-in by using the client-side rendering technology in SharePoint.
1010

11-
11+
In SharePoint, client-side rendering provides a way for you to produce your own output for a set of controls that are hosted on a SharePoint page. It enables you to use well-known technologies, such as HTML and JavaScript, to define the rendering logic of SharePoint list views. With client-side rendering, you can specify your own JavaScript resources and host them in the data storage options that are available to your add-ins, such as in a document library. A SharePoint-hosted add-in includes only SharePoint components. A SharePoint-hosted add-in has its resources in an isolated subsite of the host web, called the add-in web.
1212

13-
In SharePoint, client-side rendering provides a way for you to produce your own output for a set of controls that are hosted in a SharePoint page. It enables you to use well-known technologies, such as HTML and JavaScript, to define the rendering logic of SharePoint list views. With client-side rendering, you can specify your own JavaScript resources and host them in the data storage options that are available to your add-ins, such as in a document library. A SharePoint-hosted add-in includes only SharePoint components. A SharePoint-hosted add-in has its resources in an isolated subsite of the host web, called the add-in web.
14-
13+
<a name="SP15CSRlistview_Prereq"> </a>
1514

1615
## Prerequisites for using the examples in this article
17-
<a name="SP15CSRlistview_Prereq"> </a>
1816

19-
To follow the steps in this example, you will need the following:
20-
17+
To follow the steps in this example, you need the following:
2118

22-
19+
- [Visual Studio 2015 and the latest Microsoft Office Developer Tools ](https://www.visualstudio.com/vs/office-tools/)
2320

24-
- [Visual Studio 2015 and the latest Microsoft Office Developer Tools ](https://www.visualstudio.com/features/office-tools-vs)
25-
26-
2721
- A SharePoint development environment (add-in isolation required for on-premises scenarios)
28-
29-
30-
For guidance on how to set up a development environment that fits your needs, see [Start building Office and SharePoint Add-ins](http://msdn.microsoft.com/library/187f8c8c-1b15-471c-80b5-69a40e67deea.aspx).
31-
3222

33-
23+
For guidance about how to set up a development environment that fits your needs, see [Two types of SharePoint Add-ins: SharePoint-hosted and provider-hosted](sharepoint-add-ins.md#two-types-of-sharepoint-add-ins-sharepoint-hosted-and-provider-hosted).
3424

3525
### Core concepts to help you understand list view customization with client-side rendering
3626

@@ -42,201 +32,168 @@ The following table lists useful articles that can help you understand the conce
4232
| [UX design for SharePoint Add-ins](ux-design-for-sharepoint-add-ins.md)|Learn about the UX options that you have when you are building SharePoint Add-ins.|
4333
| [Host webs, add-in webs, and SharePoint components in SharePoint](host-webs-add-in-webs-and-sharepoint-components-in-sharepoint.md)|Learn about the difference between host webs and add-in webs. Find out which SharePoint components can be included in a SharePoint Add-in, which components are deployed to the host web, which components are deployed to the add-in web, and how the add-in web is deployed in an isolated ___domain.|
4434

45-
## Code example: Customize a list view by using client-side rendering
4635
<a name="SP15CSRlistview_Codeexample"> </a>
4736

48-
To customize a list view that is deployed to the add-in web by using client-side rendering, follow these steps:
49-
37+
## Code example: Customize a list view by using client-side rendering
5038

51-
39+
The following steps show you how to customize a list view that is deployed to the add-in web by using client-side rendering.
5240

5341
1. Create the SharePoint Add-in project.
54-
55-
42+
5643
2. Create a new list definition with a custom view.
57-
58-
59-
3. Provide the custom rendering logic in a JavaScript file.
60-
61-
62-
Figure 1 shows a client-side rendered view of an announcements list.
63-
6444

65-
45+
3. Provide the custom rendering logic in a JavaScript file.
6646

67-
**Figure 1. Custom view of an announcements list**
47+
The following figure shows a client-side rendered view of an announcements list.
6848

69-
49+
**Custom view of an announcements list**
7050

71-
7251
![Custom view of an announcements list](../images/CSRListView_result.png)
73-
7452

7553
### To create the SharePoint Add-in project
7654

55+
1. Open Visual Studio 2015 as administrator. (To do this, right-click the **Visual Studio** icon on the **Start** menu, and select **Run as administrator**.)
7756

78-
1. Open Visual Studio 2015 as administrator. (To do this, right-click the **Visual Studio** icon on the **Start** menu, and choose **Run as administrator**.)
79-
80-
81-
2. Create a new project using the **SharePoint Add-in** template.
57+
2. Create a new project using the **SharePoint Add-in** template.
8258

83-
Figure 2 shows the ___location of the **SharePoint Add-in** template in Visual Studio 2015, under **Templates**, **Visual C#**, **Office/SharePoint**, **Office Add-ins**.
59+
The following figure shows the ___location of the **SharePoint Add-in** template in Visual Studio 2015, under **Templates** > **Visual C#** > **Office/SharePoint** > **Office Add-ins**.
8460

61+
**Add-in for SharePoint Visual Studio template**
8562

86-
**Figure 2. Add-in for SharePoint Visual Studio template**
63+
![App for SharePoint Visual Studio template](../images/AppForSharePointVSTemplate.PNG)
8764

88-
89-
90-
![App for SharePoint Visual Studio template](../images/AppForSharePointVSTemplate.PNG)
91-
92-
93-
94-
95-
9665
3. Provide the URL of the SharePoint website that you want to use for debugging.
9766

98-
99-
4. Select **SharePoint-hosted** as the hosting option for your add-in.
100-
101-
67+
4. Select **SharePoint-hosted** as the hosting option for your add-in.
10268

10369
### To create a new list definition
10470

71+
1. Right-click the SharePoint Add-in project, and add a new **List** item. Create a customizable list based on Announcements.
10572

106-
1. Right-click the SharePoint Add-in project, and add a new **List** item. Create a customizable list based on Announcements.
107-
108-
109-
2. Copy the following markup and paste it in the **Views** element in the Schema.xml file of your list feature. The markup performs the following tasks:
73+
2. Copy the following markup and paste it in the **Views** element in the Schema.xml file of your list feature. The markup performs the following tasks:
11074

111-
- Declares a new view named Overridable with a BaseViewID=2.
112-
113-
114-
- Provides a value for the **JSLink** element that points to a JavaScript file that is provisioned with the add-in.
75+
- Declares a new view named Overridable with a BaseViewID=2.
76+
77+
- Provides a value for the **JSLink** element that points to a JavaScript file that is provisioned with the add-in.
11578

11679
> [!NOTE]
11780
> The JSLink property is not supported on Survey or Events lists. A SharePoint calendar is an Events list.
11881
119-
```XML
120-
<View BaseViewID="2"
121-
Name="8d2719f3-c3c3-415b-989d-33840d8e2ddb"
122-
DisplayName="Overridable"
123-
Type="HTML"
124-
WebPartZoneID="Main"
125-
SetupPath="pages\viewpage.aspx"
126-
Url="Overridable.aspx"
127-
DefaultView="TRUE">
128-
<ViewFields>
129-
<FieldRef Name="Title" />
130-
</ViewFields>
131-
<Query />
132-
<Toolbar Type="Standard" />
133-
<XslLink>main.xsl</XslLink>
134-
<JSLink Default="TRUE">~site/Scripts/CSRListView.js</JSLink>
135-
</View>
136-
```
137-
82+
```XML
83+
<View BaseViewID="2"
84+
Name="8d2719f3-c3c3-415b-989d-33840d8e2ddb"
85+
DisplayName="Overridable"
86+
Type="HTML"
87+
WebPartZoneID="Main"
88+
SetupPath="pages\viewpage.aspx"
89+
Url="Overridable.aspx"
90+
DefaultView="TRUE">
91+
<ViewFields>
92+
<FieldRef Name="Title" />
93+
</ViewFields>
94+
<Query />
95+
<Toolbar Type="Standard" />
96+
<XslLink>main.xsl</XslLink>
97+
<JSLink Default="TRUE">~site/Scripts/CSRListView.js</JSLink>
98+
</View>
99+
```
100+
101+
<br/>
138102

139103
### To provide the custom rendering logic in a JavaScript file
140104

105+
1. Right-click the **Scripts** folder, and add a new JavaScript file. Name the file **CSRListView.js**.
141106

142-
1. Right-click the **Scripts** folder, and add a new JavaScript file. Name the fileCSRListView.js.
143-
144-
145107
2. Copy the following code and paste it in the CSRListView.js file. The code performs the following tasks:
146108

147-
- Provides event handlers for the **PreRender** and **PostRender** events.
148-
149-
150-
- Provides templates for the Header, Footer, and Item template sets.
151-
152-
153-
- Registers the templates.
154-
155-
109+
- Provides event handlers for the **PreRender** and **PostRender** events.
156110

157-
```
158-
(function () {
159-
// Initialize the variable that stores the objects.
160-
var overrideCtx = {};
161-
overrideCtx.Templates = {};
111+
- Provides templates for the Header, Footer, and Item template sets.
162112

163-
// Assign functions or plain html strings to the templateset objects:
164-
// header, footer and item.
165-
overrideCtx.Templates.Header = "<B><#=ctx.ListTitle#></B>" +
166-
"<hr><ul id='unorderedlist'>";
113+
- Registers the templates.
167114

168-
// This template is assigned to the CustomItem function.
169-
overrideCtx.Templates.Item = customItem;
170-
overrideCtx.Templates.Footer = "</ul>";
115+
```js
116+
117+
(function () {
118+
// Initialize the variable that stores the objects.
119+
var overrideCtx = {};
120+
overrideCtx.Templates = {};
171121

172-
// Set the template to the:
173-
// Custom list definition ID
174-
// Base view ID
175-
overrideCtx.BaseViewID = 2;
176-
overrideCtx.ListTemplateType = 10057;
122+
// Assign functions or plain html strings to the templateset objects:
123+
// header, footer and item.
124+
overrideCtx.Templates.Header = "<B><#=ctx.ListTitle#></B>" +
125+
"<hr><ul id='unorderedlist'>";
177126

178-
// Assign a function to handle the
179-
// PreRender and PostRender events
180-
overrideCtx.OnPreRender = preRenderHandler;
181-
overrideCtx.OnPostRender = postRenderHandler;
127+
// This template is assigned to the CustomItem function.
128+
overrideCtx.Templates.Item = customItem;
129+
overrideCtx.Templates.Footer = "</ul>";
182130

183-
// Register the template overrides.
184-
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
185-
})();
131+
// Set the template to the:
132+
// Custom list definition ID
133+
// Base view ID
134+
overrideCtx.BaseViewID = 2;
135+
overrideCtx.ListTemplateType = 10057;
186136

187-
// This function builds the output for the item template.
188-
// It uses the context object to access announcement data.
189-
function customItem(ctx) {
137+
// Assign a function to handle the
138+
// PreRender and PostRender events
139+
overrideCtx.OnPreRender = preRenderHandler;
140+
overrideCtx.OnPostRender = postRenderHandler;
190141

191-
// Build a listitem entry for every announcement in the list.
192-
var ret = "<li>" + ctx.CurrentItem.Title + "</li>";
193-
return ret;
194-
}
142+
// Register the template overrides.
143+
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
144+
})();
195145

196-
// The preRenderHandler attends the OnPreRender event
197-
function preRenderHandler(ctx) {
146+
// This function builds the output for the item template.
147+
// It uses the context object to access announcement data.
148+
function customItem(ctx) {
198149

199-
// Override the default title with user input.
200-
ctx.ListTitle = prompt("Type a title", ctx.ListTitle);
201-
}
150+
// Build a listitem entry for every announcement in the list.
151+
var ret = "<li>" + ctx.CurrentItem.Title + "</li>";
152+
return ret;
153+
}
202154

203-
// The postRenderHandler attends the OnPostRender event
204-
function postRenderHandler(ctx) {
155+
// The preRenderHandler attends the OnPreRender event
156+
function preRenderHandler(ctx) {
205157

206-
// You can manipulate the DOM in the postRender event
207-
var ulObj;
208-
var i, j;
158+
// Override the default title with user input.
159+
ctx.ListTitle = prompt("Type a title", ctx.ListTitle);
160+
}
209161

210-
ulObj = document.getElementById("unorderedlist");
211-
212-
// Reverse order the list.
213-
for (i = 1; i < ulObj.children.length; i++) {
214-
var x = ulObj.children[i];
215-
for (j = 1; j < ulObj.children.length; j++) {
216-
var y = ulObj.children[j];
217-
if(x.innerText<y.innerText){
218-
ulObj.insertBefore(y, x);
162+
// The postRenderHandler attends the OnPostRender event
163+
function postRenderHandler(ctx) {
164+
165+
// You can manipulate the DOM in the postRender event
166+
var ulObj;
167+
var i, j;
168+
169+
ulObj = document.getElementById("unorderedlist");
170+
171+
// Reverse order the list.
172+
for (i = 1; i < ulObj.children.length; i++) {
173+
var x = ulObj.children[i];
174+
for (j = 1; j < ulObj.children.length; j++) {
175+
var y = ulObj.children[j];
176+
if(x.innerText<y.innerText){
177+
ulObj.insertBefore(y, x);
178+
}
219179
}
220180
}
221181
}
222-
}
223-
```
182+
```
224183

184+
<br/>
225185

226186
### To build and run the solution
227187

228-
229-
1. Press the F5 key.
188+
1. Select the F5 key.
230189

231190
> [!NOTE]
232-
> When you press F5, Visual Studio builds the solution, deploys the add-in, and opens the permissions page for the add-in.
191+
> When you select F5, Visual Studio builds the solution, deploys the add-in, and opens the permissions page for the add-in.
233192

234-
2. Choose the **Trust It** button.
235-
193+
2. Select the **Trust It** button.
236194

237-
3. Go to your custom List by entering the _/Lists/<your_list_instance>_ address relative to your add-in directory in the add-in web ___domain (not the host web ___domain). Add one or two announcements. On the ribbon, choose the **Overridable** view.
195+
3. Go to your custom List by entering the _/Lists/<your_list_instance>_ address relative to your add-in directory in the add-in web ___domain (not the host web ___domain). Add one or two announcements. On the ribbon, select the **Overridable** view.
238196

239-
240197
## See also
241198
<a name="SP15CSRlistview_AddResources"> </a>
242199

0 commit comments

Comments
 (0)