customizing the sharepoint 2013 user interface with javascript - chris obrien

39
Customising the SharePoint 2013 UI with JavaScript P&M306 Chris O’Brien - MVP

Upload: chris-obrien

Post on 08-May-2015

10.109 views

Category:

Technology


4 download

DESCRIPTION

Covers several approaches for user interface customization in SP2013 - using JSLink to customize a list and/or view, creating custom Display Templates for the Content Search web part, and different approaches for customizing the search hover panel.

TRANSCRIPT

Page 1: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Customising the SharePoint 2013 UI with JavaScript

P&M306

Chris O’Brien - MVP

Page 2: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

About me Independent Consultant Head of Development, Content and Code

Blog: www.sharepointnutsandbolts.com Twitter: @ChrisO_Brien LinkedIn: http://uk.linkedin.com/in/

chrisobrienmvp

Page 3: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Long Ago…

SharePoint 2007

CAML

SharePoint 2010

XSL

Page 4: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

SharePoint 2010

XSL

…Today

SharePoint 2013

CSR

Page 5: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Client-Side Rendering

(CSR)

JSLink

Display Templates

Terminology

Page 6: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

• Content Search web part

• Search hover panel

• List callouts

• Lists

• Fields

• Web parts etc..

Client-Side

Rendering (CSR)

JSLink

Display Templates

Terminology

Page 7: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Used to transform: Lists Views Fields Web Parts Content types

JSLink

Page 8: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Registering templates/running code

The RenderContext JS object: Templates collection

– e.g. header, item, footer– Register with BaseViewID, ListTemplateType, ControlMode

OnPreRender OnPostRender

ListData ListSchema

Page 9: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Demo

USING JSLINK TO FORMAT A LIST VIEW

Page 10: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Demo screenshot:

A SharePoint list transformed with JSLink (jQuery UI accordion)

Page 11: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Demo screenshot:

A SharePoint field transformed with JSLink (simple conditional formatting)

Page 12: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Advanced CSR possibilities

Modify list data/schema in OnPreRender E.g. lookup something dynamically

Use SPClientRenderer.Render() to obtain HTML: From arbitrary data Outside of page context In AJAX methods

Page 13: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Customizing the Content Search web part

Page 14: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Content Query vs. Content SearchContent Query web

partContent Search web part

Latency

Scope

Styling

Bonuses

100% up-to-date Depends on crawl frequency/speed

Current site collection Entire farm/tenancy

XSLT JavaScript

Parameterisation

Support for slideshow, paging

Page 15: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

CSWP - 5 ‘easy to nail’ requirements

1. “More like this” (Items matching a tag)

2. Recently changed items

3. Most popular items

4. “(Recent) items you may be interested in”(Matching current user’s profile)

5. “Items related to you”(Contributor to document)

Page 16: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

CSWP options

“Unique instance”

•Configure query in web

part properties

“Reusable result set”

•Use Result Source

(OOTB or custom)

Page 17: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

The role of Managed Properties CSWP has mappings to Managed Props

for data:

Page 18: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

CSWP and Display Templates

These items are files in

~sitecollection/_catalogs/masterpage

/Display Templates/

Content Web Parts

Page 19: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Diagnostic item template

Diagnostic template gives raw (ish) output

Tip: configure many props temporarily

Page 20: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Demo

CUSTOMISING THE CONTENT SEARCH WEB PART

Page 21: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Demo screenshot:

Content Search web part with default Display Template

Page 22: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Demo screenshot:

Content Search web part with custom Display Template

Page 23: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Dynamic values in query

{User}

•Match profile field e.g.

User.Department

{Page}

•Match field value e.g.

Page.MyField

{Site}

•Match current site e.g. Site.Url

{Today}

•Date filtering e.g. Today-7

{Term}

•Match current managed nav

term

Several tokens available:

Page 24: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Script/CSS in display templates

Tools: $includeScript $includeLanguageScript $includeCSS

But consider HTTP payload – may be better combining with other CSS/JS

Page 25: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Search hover panel

Page 26: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

SP2013 search recap

•Search scope on steroidsResult Source

•Best Bet on steroidsQuery Rule

•E.g. Word doc, person, social post etc.Result Type

•Visual rendering of an itemDisplay Template

Page 27: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Search display templates

1. Create the Display Template Copy/rename then edit 2 files:

– Item_Something.js [HTML]– Item_Something_HoverPanel.js [HTML]

2. Create any core search config E.g. Managed Properties, Result Source

3. Create the Result Type

Alternative - use search

results WP properties to map

to Display Template

Page 28: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Hover Panel components

Page 29: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Hover Panel components

- Item_CommonHoverPanel_Body.js

- Item_[FileType]_HoverPanel.js

Page 30: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Hover Panel actions

Footer actions can also be Common Specific

Gotcha! Some item types do not use Common actions E.g. Discussion

- Item_CommonHoverPanel_Actions.js

- Item_[FileType]_HoverPanel.js

Page 31: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Demo

CUSTOMISING THE SEARCH HOVER PANEL

Page 32: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Demo screenshot:

Search hover panel customized for CAD files (i.e. custom behaviour for a specific content type)

Page 33: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

2nd demo, screenshot 1:

Adding a new action in the search hover panel footer:

Page 34: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

2nd demo, screenshot 2:

Clicking action fades in a textbox and button:

Page 35: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

2nd demo, screenshot 3:

Clicking ‘Post’ button posts to user’s social feed:

Page 36: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

2nd demo, screenshot 4:

Message in user’s feed:

Page 37: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Hover panel – lessons learnt

Can’t use document.ready() – DOM is not populated Specify function in ctx.OnPostRender instead These functions are called ONCE (on first render

[mouseover])– N.B. Array of functions is accessible in all files e.g. header, body,

actions etc.

DON’T delete _#= ctx.RenderBody(ctx) =#_ This executes Item_CommonHoverPanel_Body.js

(inheritance model)

Page 38: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Summary

JavaScript is key to many SP2013 UI elements Examples shown:

Customising entire list UI Conditional formatting of a field Rendering of Content Search web part Customising search hover panel (inc. AJAX)

Lots of other possibilities too!

Page 39: Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien

Thank you for attending!

www.sharepointnutsandbolts.com

@ChrisO_Brien